Jacek Caban : atl: Allow only ASCII digit for registrar binary values.
Alexandre Julliard
julliard at winehq.org
Thu Feb 6 15:44:17 CST 2020
Module: wine
Branch: master
Commit: ffbb1c4eb44c569a4c27ef69d2f4b787dc5e6566
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ffbb1c4eb44c569a4c27ef69d2f4b787dc5e6566
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu Feb 6 14:13:21 2020 +0100
atl: Allow only ASCII digit for registrar binary values.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/atl/registrar.c | 17 +++++++++++------
dlls/atl/tests/registrar.c | 4 ++--
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/dlls/atl/registrar.c b/dlls/atl/registrar.c
index 612274d1a9..586cce3201 100644
--- a/dlls/atl/registrar.c
+++ b/dlls/atl/registrar.c
@@ -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,
diff --git a/dlls/atl/tests/registrar.c b/dlls/atl/tests/registrar.c
index 4ecb092fd6..f9ec9529dd 100644
--- a/dlls/atl/tests/registrar.c
+++ b/dlls/atl/tests/registrar.c
@@ -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]);
More information about the wine-cvs
mailing list