[REGEDIT] Fix issue at Find registry key (#4341)
authorJose Carlos Jesus <zecarlos1957@hotmail.com>
Sun, 19 Jun 2022 19:57:30 +0000 (20:57 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Jun 2022 19:57:30 +0000 (21:57 +0200)
- If we dont select a item as a starting point to search from, we need to set
  pszValueName to the first value name in current subkey.

- Check pszSubKey length before calling RegFindRecurse.

- Set focus to subkey when we search for it.

base/applications/regedit/find.c

index 1fb5bbe..17de9b9 100644 (file)
@@ -160,9 +160,6 @@ BOOL RegFindRecurse(
     if (lResult != ERROR_SUCCESS)
         return FALSE;
 
-    if (pszValueName == NULL)
-        pszValueName = s_empty;
-
     lResult = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL,
                               &c, NULL, NULL, NULL, NULL);
     if (lResult != ERROR_SUCCESS)
@@ -195,6 +192,9 @@ BOOL RegFindRecurse(
 
     qsort(ppszNames, c, sizeof(LPWSTR), compare);
 
+    if (pszValueName == NULL)
+        pszValueName = ppszNames[0];
+
     for(i = 0; i < c; i++)
     {
         if (DoEvents())
@@ -370,13 +370,14 @@ BOOL RegFindWalk(
     LPWSTR *ppszNames = NULL;
 
     hBaseKey = *phKey;
+
+    if (wcslen(pszSubKey) >= _countof(szSubKey))
+        return FALSE;
+
     if (RegFindRecurse(hBaseKey, pszSubKey, pszValueName, ppszFoundSubKey,
                        ppszFoundValueName))
         return TRUE;
 
-    if (wcslen(pszSubKey) >= MAX_PATH)
-        return FALSE;
-
     wcscpy(szSubKey, pszSubKey);
     while(szSubKey[0] != 0)
     {
@@ -687,10 +688,18 @@ BOOL FindNext(HWND hWnd)
     {
         GetKeyName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey);
         SelectNode(g_pChildWnd->hTreeWnd, szFullKey);
-        SetValueName(g_pChildWnd->hListWnd, pszFoundValueName);
         free(pszFoundSubKey);
-        free(pszFoundValueName);
-        SetFocus(g_pChildWnd->hListWnd);
+
+        if (pszFoundValueName != NULL)
+        {
+            SetValueName(g_pChildWnd->hListWnd, pszFoundValueName);
+            free(pszFoundValueName);
+            SetFocus(g_pChildWnd->hListWnd);
+        }
+        else
+        {
+            SetFocus(g_pChildWnd->hTreeWnd);
+        }
     }
     return fSuccess || s_bAbort;
 }