Non-portable regex in drivedb.h (was: Re: smartmontools update database error)

Rainer Müller raimue at macports.org
Fri Feb 22 14:18:39 PST 2013


Hello,

at MacPorts we got a report about a problem with the latest drivedb.h
used by smartmontools:

On 2013-02-19 05:16, Chris Murphy wrote:
> chris$ update-smart-drivedb 
> /opt/local/share/smartmontools/drivedb.h.error: rejected by /opt/local/sbin/smartctl, probably no longer compatible
> 
> I get the same error prefacing with sudo. This is smartmontools 6.0, built with Macports 2.1.3, XCode 4.6, on 10.8.2. 

I produced a more verbose error message by trying to load the downloaded
file manually:

$ smartctl -B /opt/local/share/smartmontools/drivedb.h.error
/opt/local/share/smartmontools/drivedb.h.error(165): Error in regular
expression: empty (sub)expression

Line 165 of this file contains the following regex:

    "C300-CTFDDA[AC](064|128|256)MAG|", // tested with [...]

I guess the smartmontools code uses regex(3) from libc. According to the
man page for the regex functions on my Mac OS X 10.8.2 [1], the empty
subexpression used here is not valid:

    `|' cannot appear first or last in a (sub)expression or after
    another `|', i.e., an operand of `|' cannot be an empty
    subexpression.

This might work on Linux with glibc or on other *BSD systems, I did no
extensive testing. However, the regex format used in drivedb.h here is
not portable and does not work on Mac OS X.

I now suggest to solve this issue upstream as for MacPorts, there is not
much we can do about the format of the driverdb.h or about the regex(3)
interface offered by libc.

My suggested fix would be to write this using an empty parenthesized
subexpression, as that is explicitely allowed in the man page
immediately following the statement quoted above:

    An empty parenthesized subexpression, `()', is legal and matches
    an empty (sub)string.  An empty string is not a legal RE.

So the correct syntax for the line above could be:

    "C300-CTFDDA[AC](064|128|256)MAG|()", // tested with [...]

I verified that if I change this single line in the file, I can load the
updated database using smartctrl -B. I did not test this on Linux or
*BSD, but I assume that the proposed change would be a valid regex for
all of them.

Rainer

[1] A slightly older version of the regex(3) man page from Mac OS X can
be viewed online:
https://developer.apple.com/library/mac/#documentation/darwin/reference/manpages/man3/regex.3.html


More information about the macports-users mailing list