stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Black <abl...@roguewave.com>
Subject Re: exec util testing commands [patch]
Date Wed, 02 Aug 2006 21:47:17 GMT
Greetings

One more take on this patch, hopefully the final.  I think I've 
addressed all the concerns presented here.

--Andrew Black

Martin Sebor wrote:
> Andrew Black wrote:
>> Ok...
>>
>> I've tried to address the issues noted below in the attached (revised) 
>> version of the test_switches.diff patch.  In the process of testing 
>> the modifications, I discovered a bug with how get_signo and 
>> get_signame determine the end of the array.  That bug has also been 
>> resolved in this revised patch.
>>
> 
> Goody! :)
> 
>> +const int
>> +get_signo (const char* signame)
>> +{
>>      size_t i;
>> +    int trans;
>> +    char *junk;
>> +
>> +    assert (0 != signame);
>> +
>> +    if ('s' == tolower (signame [0]) && 'i' == tolower (signame [1]) 
> 
> I'm afraid this is unsafe when char is a signed type. tolower() takes
> an int but the behavior of the function is undefined when the argument
> is neither EOF or representable in unsigned char.
> 
> The safe way to use these functions is to convert the character to
> unsigned char first:
> 
>     typedef unsigned char UChar;
>     if (   's' == tolower ((UChar)signame [0])
>         && 'i' == tolower ((UChar)signame [1])
> 
> 
>> +        && 'g' == tolower (signame [2]))
>> +        signame += 3;
>> +    +    if ('#' == signame [0])
>> +        ++signame;
>> +    +    trans = strtol (signame, &junk, 0);
> 
> Did you really intend to accept things like SIG#0xa and interpret
> input such as SIG#011 as octal? I would expect this function (and
> probably all the rest) to handle only decimal numbers and reject
> anything else.
> 
>> +
>> +    if (0 == *junk && 0 == errno)
>> +        return trans;
>> +
>> +    for (i = 0; signal_names [i].str; ++i) {
>> +        if (0 == strcasecmp (signal_names [i].str, signame)) {
> 
> strcasecmp() is non-standard, we can't use it. AFAIK, there's no
> standard case-insensitive string comparison function in C or in
> POSIX.
> 
> Could you please fix these and resubmit?
> 
> Thanks
> Martin

Mime
View raw message