setupapi: Fix hex digit check in SetupGetBinaryField.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-02-06 14:00:33 +01:00 committed by Alexandre Julliard
parent bf95bccfaf
commit d580d2c2fd
1 changed files with 12 additions and 3 deletions

View File

@ -1803,6 +1803,15 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result )
}
static int xdigit_to_int(WCHAR c)
{
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
if ('A' <= c && c <= 'F') return c - 'A' + 10;
return -1;
}
/***********************************************************************
* SetupGetBinaryField (SETUPAPI.@)
*/
@ -1837,15 +1846,15 @@ BOOL WINAPI SetupGetBinaryField( PINFCONTEXT context, DWORD index, BYTE *buffer,
{
const WCHAR *p;
DWORD value = 0;
for (p = field->text; *p && iswxdigit(*p); p++)
int d;
for (p = field->text; *p && (d = xdigit_to_int(*p)) != -1; p++)
{
if ((value <<= 4) > 255)
{
SetLastError( ERROR_INVALID_DATA );
return FALSE;
}
if (*p <= '9') value |= (*p - '0');
else value |= (towlower(*p) - 'a' + 10);
value |= d;
}
buffer[i - index] = value;
}