reg: Fail if the data value passed with REG_DWORD will cause an overflow

Hugh McMaster hugh.mcmaster at outlook.com
Sat Feb 20 01:39:56 CST 2016


On Sat, 20 Feb 2016 13:54:49 +0900, Alexandre Julliard wrote:
> 
> Hugh McMaster writes:
> 
>> @@ -243,8 +243,17 @@ static LPBYTE get_regdata(LPWSTR data, DWORD reg_type, WCHAR separator, DWORD *r
>>          {
>>              LPWSTR rest;
>>              DWORD val;
>> +            BOOL overflow = FALSE;
>> +            if (data[1] == 'x')
>> +            {
>> +                WCHAR *ptr = &data[2];
>> +                while (*ptr == '0')
>> +                    ptr++;
>> +                if (strlenW(ptr)> 8)
>> +                    overflow = TRUE;
>> +            }
>>              val = strtoulW(data, &rest, (data[1] == 'x') ? 16 : 10);
> 
> You won't be able to catch base 10 overflows this way. It probably needs
> a more general solution (and some more test cases...)

That's a good point. The best solution would be to check if (val == ULONG_MAX && errno == ERANGE),
but it seems our strtoulW implementation doesn't have errno support.

According to the C89 standard, "The strtoul function returns the converted value, if any.  If no
conversion could be performed, zero is returned.  If the correct value
would cause overflow, ULONG_MAX is returned, and the value of the
macro ERANGE is stored in errno ." [1]

Setting errno shouldn't be difficult, but I can research other solutions too, if you like.

If I do set errno for strtoulW, I'll set it for strtolW as well.

[1] http://port70.net/~nsz/c/c89/c89-draft.html#4.10.1.6
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20160220/5e4aa5e3/attachment.html>


More information about the wine-devel mailing list