[PATCH 2/7] reg: Check key paths in main
Jonathan Vollebregt
jnvsor at gmail.com
Tue Nov 4 14:15:09 CST 2014
Checks against backslashes at the start and end of a key.
---
programs/reg/reg.c | 44 ++++++++++++++++++++++++++++++++------------
programs/reg/reg.rc | 2 +-
programs/reg/tests/reg.c | 4 ++--
3 files changed, 35 insertions(+), 15 deletions(-)
mode change 100644 => 100755 programs/reg/reg.c
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
old mode 100644
new mode 100755
index 905b484..cfaa62b
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -20,6 +20,8 @@
#include <wine/unicode.h>
#include "reg.h"
+#define ERROR_NO_REMOTE 20000
+
static int reg_printfW(const WCHAR *msg, ...)
{
va_list va_args;
@@ -79,6 +81,8 @@ static int reg_print_error(LONG error_code)
return reg_message(STRING_INVALID_KEY);
case ERROR_BAD_COMMAND:
return reg_message(STRING_INVALID_CMDLINE);
+ case ERROR_NO_REMOTE:
+ return reg_message(STRING_NO_REMOTE);
default:
{
static const WCHAR error_string[] = {'%','0','5','d',':',' ','%','s',0};
@@ -200,12 +204,6 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
reg_printfW(stubW, key_name, value_name, value_empty, type, data, force);
- if (key_name[0]=='\\' && key_name[1]=='\\')
- {
- reg_message(STRING_NO_REMOTE);
- return 1;
- }
-
p = strchrW(key_name,'\\');
if (!p)
{
@@ -273,12 +271,6 @@ static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
,0};
reg_printfW(stubW, key_name, value_name, value_empty, value_all, force);
- if (key_name[0]=='\\' && key_name[1]=='\\')
- {
- reg_message(STRING_NO_REMOTE);
- return 1;
- }
-
p = strchrW(key_name,'\\');
if (!p)
{
@@ -393,6 +385,25 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
return 1;
}
+static BOOL sane_path(const WCHAR *key)
+{
+ int i = strlenW(key);
+
+ if (i < 3 || (key[i - 1] == '\\' && key[i - 2] == '\\'))
+ {
+ reg_print_error(ERROR_BADKEY);
+ return FALSE;
+ }
+
+ if (key[0] == '\\' && key[1] == '\\' && key[2] != '\\')
+ {
+ reg_print_error(ERROR_NO_REMOTE);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
int wmain(int argc, WCHAR *argvW[])
{
int i;
@@ -435,6 +446,9 @@ int wmain(int argc, WCHAR *argvW[])
}
key_name = argvW[2];
+ if (!sane_path(key_name))
+ return 1;
+
for (i = 1; i < argc; i++)
{
if (!lstrcmpiW(argvW[i], slashVW))
@@ -471,6 +485,9 @@ int wmain(int argc, WCHAR *argvW[])
}
key_name = argvW[2];
+ if (!sane_path(key_name))
+ return 1;
+
for (i = 1; i < argc; i++)
{
if (!lstrcmpiW(argvW[i], slashVW))
@@ -502,6 +519,9 @@ int wmain(int argc, WCHAR *argvW[])
}
key_name = argvW[2];
+ if (!sane_path(key_name))
+ return 1;
+
for (i = 1; i < argc; i++)
{
if (!lstrcmpiW(argvW[i], slashVW))
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 52fd386..74ef32e 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -33,7 +33,7 @@ STRINGTABLE
STRING_SUCCESS, "The operation completed successfully\n"
STRING_INVALID_KEY, "Error: Invalid key name\n"
STRING_INVALID_CMDLINE, "Error: Invalid command line parameters\n"
- STRING_NO_REMOTE, "Error: Unable to add keys to remote machine\n"
+ STRING_NO_REMOTE, "Error: Unable to access remote machine\n"
STRING_CANNOT_FIND, "Error: The system was unable to find the specified registry key or value\n"
STRING_ERROR, "Error: "
}
diff --git a/programs/reg/tests/reg.c b/programs/reg/tests/reg.c
index 9449429..dbc8731 100644
--- a/programs/reg/tests/reg.c
+++ b/programs/reg/tests/reg.c
@@ -120,10 +120,10 @@ static void test_add(void)
ok(err == ERROR_FILE_NOT_FOUND, "got exit code %d\n", r);
run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest2\\\\ /f", &r);
- todo_wine ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
+ ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
"got exit code %u\n", r);
err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest2");
- todo_wine ok(err == ERROR_FILE_NOT_FOUND || broken(err == ERROR_SUCCESS /* WinXP */),
+ ok(err == ERROR_FILE_NOT_FOUND || broken(err == ERROR_SUCCESS /* WinXP */),
"got exit code %d\n", r);
run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest3\\ /f", &r);
--
2.1.1
More information about the wine-patches
mailing list