Module: wine Branch: master Commit: 797520db8f7eb708845891da6f08d3030393d6bc URL: https://source.winehq.org/git/wine.git/?a=commit;h=797520db8f7eb708845891da6...
Author: Hugh McMaster hugh.mcmaster@outlook.com Date: Tue Apr 20 23:21:59 2021 +1000
reg: Fail if a system key has a trailing backslash but no subkey path.
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
programs/reg/reg.c | 16 +++++++++++++--- programs/reg/tests/add.c | 8 ++++---- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 7ed45b73ad8..69107d54b92 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -234,9 +234,6 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path) if (!sane_path(key)) return FALSE;
- *path = wcschr(key, '\'); - if (*path) (*path)++; - *root = path_get_rootkey(key); if (!*root) { @@ -244,6 +241,19 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path) return FALSE; }
+ *path = wcschr(key, '\'); + + if (!*path) + return TRUE; + + (*path)++; + + if (!**path) + { + output_message(STRING_INVALID_SYSTEM_KEY); + return FALSE; + } + return TRUE; }
diff --git a/programs/reg/tests/add.c b/programs/reg/tests/add.c index 36b5f821350..6973eefd892 100644 --- a/programs/reg/tests/add.c +++ b/programs/reg/tests/add.c @@ -311,12 +311,12 @@ static void test_key_formats(void)
/* Test validity of trailing backslash after system key */ run_reg_exe("reg add HKCU\ /v Value1 /t REG_SZ /d foo /f", &r); - todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - todo_wine verify_reg_nonexist(HKEY_CURRENT_USER, "Value1"); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + verify_reg_nonexist(HKEY_CURRENT_USER, "Value1");
run_reg_exe("reg add HKEY_CURRENT_USER\ /v Value2 /t REG_SZ /d bar /f", &r); - todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - todo_wine verify_reg_nonexist(HKEY_CURRENT_USER, "Value2"); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + verify_reg_nonexist(HKEY_CURRENT_USER, "Value2"); }
static void test_add(void)