Hugh McMaster : reg: Dynamically allocate memory for the value name buffer when deleting all registry values in a specified key.

Alexandre Julliard julliard at winehq.org
Tue Aug 8 07:36:37 CDT 2017


Module: wine
Branch: master
Commit: 8abec73530bff8129b3a4a07d196b44e8cf4fa5b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8abec73530bff8129b3a4a07d196b44e8cf4fa5b

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Mon Aug  7 12:28:44 2017 +0000

reg: Dynamically allocate memory for the value name buffer when deleting all registry values in a specified key.

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/reg/reg.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index c086763..37ac193 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -482,40 +482,35 @@ static int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name
 
     if (value_all)
     {
-        LPWSTR szValue;
-        DWORD maxValue;
-        DWORD count;
+        DWORD max_value_len = 256, value_len;
+        WCHAR *value_name;
         LONG rc;
 
-        rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL,
-                              NULL, &maxValue, NULL, NULL, NULL);
-        if (rc != ERROR_SUCCESS)
-        {
-            RegCloseKey(key);
-            output_message(STRING_GENERAL_FAILURE);
-            return 1;
-        }
-        maxValue++;
-        szValue = heap_xalloc(maxValue * sizeof(WCHAR));
+        value_name = heap_xalloc(max_value_len * sizeof(WCHAR));
 
         while (1)
         {
-            count = maxValue;
-            rc = RegEnumValueW(key, 0, szValue, &count, NULL, NULL, NULL, NULL);
+            value_len = max_value_len;
+            rc = RegEnumValueW(key, 0, value_name, &value_len, NULL, NULL, NULL, NULL);
             if (rc == ERROR_SUCCESS)
             {
-                rc = RegDeleteValueW(key, szValue);
+                rc = RegDeleteValueW(key, value_name);
                 if (rc != ERROR_SUCCESS)
                 {
-                    heap_free(szValue);
+                    heap_free(value_name);
                     RegCloseKey(key);
                     output_message(STRING_VALUEALL_FAILED, key_name);
                     return 1;
                 }
             }
+            else if (rc == ERROR_MORE_DATA)
+            {
+                max_value_len *= 2;
+                value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR));
+            }
             else break;
         }
-        heap_free(szValue);
+        heap_free(value_name);
     }
     else if (value_name || value_empty)
     {




More information about the wine-cvs mailing list