[PATCH 2/2] regedit: Null-terminate REG_EXPAND_SZ and REG_MULTI_SZ data if the parsed hex data does not end in a null-terminating character

Hugh McMaster hugh.mcmaster at outlook.com
Thu Jul 6 04:17:10 CDT 2017


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/regedit/regproc.c       | 19 ++++++++++++++-----
 programs/regedit/tests/regedit.c | 18 +++++++++---------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 9fe0cb81b2..9680bd24b1 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -848,13 +848,22 @@ static WCHAR *hex_data_state(struct parser *parser, WCHAR *pos)
         return line;
     }
 
-    if (!parser->is_unicode && (parser->data_type == REG_EXPAND_SZ || parser->data_type == REG_MULTI_SZ))
+    if (parser->data_type == REG_EXPAND_SZ || parser->data_type == REG_MULTI_SZ)
     {
-        void *tmp = parser->data;
+        BYTE *data = parser->data;
 
-        parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size);
-        parser->data_size *= sizeof(WCHAR);
-        HeapFree(GetProcessHeap(), 0, tmp);
+        if (data[parser->data_size - 1] != 0x00)
+        {
+            data[parser->data_size] = 0x00;
+            parser->data_size++;
+        }
+
+        if (!parser->is_unicode)
+        {
+            parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size);
+            parser->data_size *= sizeof(WCHAR);
+            HeapFree(GetProcessHeap(), 0, data);
+        }
     }
 
     set_state(parser, SET_VALUE);
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c
index 8c0f1ba545..2dfb52b5a0 100644
--- a/programs/regedit/tests/regedit.c
+++ b/programs/regedit/tests/regedit.c
@@ -382,8 +382,8 @@ static void test_basic_import(void)
     verify_reg(hkey, "Wine11a", REG_EXPAND_SZ, "%PATH%", 7, 0);
     verify_reg(hkey, "Wine11b", REG_EXPAND_SZ, "%PATH%", 7, 0);
     verify_reg(hkey, "Wine11c", REG_EXPAND_SZ, "%PATH%", 7, 0);
-    verify_reg(hkey, "Wine11d", REG_EXPAND_SZ, "%PATH", 6, TODO_REG_SIZE);
-    verify_reg(hkey, "Wine11e", REG_EXPAND_SZ, "%PATH", 6, TODO_REG_SIZE);
+    verify_reg(hkey, "Wine11d", REG_EXPAND_SZ, "%PATH", 6, 0);
+    verify_reg(hkey, "Wine11e", REG_EXPAND_SZ, "%PATH", 6, 0);
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@@ -503,8 +503,8 @@ static void test_basic_import(void)
     verify_reg(hkey, "Wine18a", REG_MULTI_SZ, "Line\0", 6, 0);
     verify_reg(hkey, "Wine18b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
     verify_reg(hkey, "Wine18c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
-    verify_reg(hkey, "Wine18d", REG_MULTI_SZ, "Line concat", 12, TODO_REG_SIZE);
-    verify_reg(hkey, "Wine18e", REG_MULTI_SZ, "Line concat", 12, TODO_REG_SIZE);
+    verify_reg(hkey, "Wine18d", REG_MULTI_SZ, "Line concat", 12, 0);
+    verify_reg(hkey, "Wine18e", REG_MULTI_SZ, "Line concat", 12, 0);
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@@ -535,8 +535,8 @@ static void test_basic_import(void)
                     "\"Wine20d\"=hex(7):4c,69,6e,65,00,\n"
                     "\"Wine20e\"=hex(7):4c,69,6e,65,00,00\n"
                     "\"Wine20f\"=hex(7):4c,69,6e,65,00,00,\n\n");
-    verify_reg(hkey, "Wine20a", REG_MULTI_SZ, "Line", 5, TODO_REG_SIZE);
-    verify_reg(hkey, "Wine20b", REG_MULTI_SZ, "Line", 5, TODO_REG_SIZE);
+    verify_reg(hkey, "Wine20a", REG_MULTI_SZ, "Line", 5, 0);
+    verify_reg(hkey, "Wine20b", REG_MULTI_SZ, "Line", 5, 0);
     verify_reg(hkey, "Wine20c", REG_MULTI_SZ, "Line", 5, 0);
     verify_reg(hkey, "Wine20d", REG_MULTI_SZ, "Line", 5, 0);
     verify_reg(hkey, "Wine20e", REG_MULTI_SZ, "Line\0", 6, 0);
@@ -548,8 +548,8 @@ static void test_basic_import(void)
                     "\"Wine21b\"=hex(2):25,50,41,54,48,25,\n"
                     "\"Wine21c\"=hex(2):25,50,41,54,48,25,00\n"
                     "\"Wine21d\"=hex(2):25,50,41,54,48,25,00,\n\n");
-    verify_reg(hkey, "Wine21a", REG_EXPAND_SZ, "%PATH%", 7, TODO_REG_SIZE);
-    verify_reg(hkey, "Wine21b", REG_EXPAND_SZ, "%PATH%", 7, TODO_REG_SIZE);
+    verify_reg(hkey, "Wine21a", REG_EXPAND_SZ, "%PATH%", 7, 0);
+    verify_reg(hkey, "Wine21b", REG_EXPAND_SZ, "%PATH%", 7, 0);
     verify_reg(hkey, "Wine21c", REG_EXPAND_SZ, "%PATH%", 7, 0);
     verify_reg(hkey, "Wine21d", REG_EXPAND_SZ, "%PATH%", 7, 0);
 
@@ -1300,7 +1300,7 @@ static void test_comments(void)
                     "  63,6f,6e,\\;comment\n"
                     "  63,61,74,;comment\n"
                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
-    verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, TODO_REG_SIZE);
+    verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
-- 
2.11.0




More information about the wine-patches mailing list