atl: Allow only ASCII digit for registrar binary values.

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:13:21 +01:00 committed by Alexandre Julliard
parent d96a0acf29
commit ffbb1c4eb4
2 changed files with 13 additions and 8 deletions

View File

@ -99,6 +99,14 @@ static void strbuf_write(LPCOLESTR str, strbuf *buf, int len)
buf->str[buf->len] = '\0';
}
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;
}
static HRESULT get_word(LPCOLESTR *str, strbuf *buf)
{
LPCOLESTR iter, iter2 = *str;
@ -303,15 +311,12 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO
break;
}
for(i = 0; i < count && buf->str[2*i]; i++) {
WCHAR digits[3];
if(!iswxdigit(buf->str[2*i]) || !iswxdigit(buf->str[2*i + 1])) {
int d1, d2;
if((d1 = xdigit_to_int(buf->str[2*i])) == -1 || (d2 = xdigit_to_int(buf->str[2*i + 1])) == -1) {
hres = E_FAIL;
break;
}
digits[0] = buf->str[2*i];
digits[1] = buf->str[2*i + 1];
digits[2] = 0;
bytes[i] = (BYTE) wcstoul(digits, NULL, 16);
bytes[i] = (d1 << 4) | d2;
}
if(SUCCEEDED(hres)) {
lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY,

View File

@ -48,7 +48,7 @@ static const char textA[] =
" val 'dword_quoted_hex' = d '0xA' \n"
" val 'dword_unquoted_hex' = d 0xA \n"
" val 'binary_quoted' = b 'deadbeef' \n"
" val 'binary_unquoted' = b deadbeef \n"
" val 'binary_unquoted' = b dead0123 \n"
" } \n"
"}";
@ -124,7 +124,7 @@ static void test_registrar(void)
size = 4;
lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
ok(bytes[0] == 0xde && bytes[1] == 0xad && bytes[2] == 0x01 && bytes[3] == 0x23,
"binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);