reg: Improve initial syntax checks during the 'export' operation.
Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
1b746c1e1c
commit
4df5c1641e
|
@ -344,27 +344,33 @@ static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
|
||||||
return hFile;
|
return hFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL is_overwrite_switch(const WCHAR *s)
|
|
||||||
{
|
|
||||||
return is_switch(s, 'y');
|
|
||||||
}
|
|
||||||
|
|
||||||
int reg_export(int argc, WCHAR *argvW[])
|
int reg_export(int argc, WCHAR *argvW[])
|
||||||
{
|
{
|
||||||
HKEY root, hkey;
|
HKEY root, hkey;
|
||||||
WCHAR *path, *long_key;
|
WCHAR *path, *long_key;
|
||||||
BOOL overwrite_file = FALSE;
|
BOOL overwrite_file = FALSE;
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
int ret;
|
int i, ret;
|
||||||
|
|
||||||
if (argc == 3 || argc > 5)
|
if (argc < 4) goto invalid;
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!parse_registry_key(argvW[2], &root, &path, &long_key))
|
if (!parse_registry_key(argvW[2], &root, &path, &long_key))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (argc == 5 && !(overwrite_file = is_overwrite_switch(argvW[4])))
|
for (i = 4; i < argc; i++)
|
||||||
goto error;
|
{
|
||||||
|
WCHAR *str;
|
||||||
|
|
||||||
|
if (argvW[i][0] != '/' && argvW[i][0] != '-')
|
||||||
|
goto invalid;
|
||||||
|
|
||||||
|
str = &argvW[i][1];
|
||||||
|
|
||||||
|
if (is_char(*str, 'y') && !str[1])
|
||||||
|
overwrite_file = TRUE;
|
||||||
|
else
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
|
||||||
if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey))
|
if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey))
|
||||||
{
|
{
|
||||||
|
@ -382,7 +388,7 @@ int reg_export(int argc, WCHAR *argvW[])
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
invalid:
|
||||||
output_message(STRING_INVALID_SYNTAX);
|
output_message(STRING_INVALID_SYNTAX);
|
||||||
output_message(STRING_FUNC_HELP, wcsupr(argvW[1]));
|
output_message(STRING_FUNC_HELP, wcsupr(argvW[1]));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -250,15 +250,17 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL is_char(const WCHAR s, const WCHAR c)
|
||||||
|
{
|
||||||
|
return (s == c || s == towupper(c));
|
||||||
|
}
|
||||||
|
|
||||||
BOOL is_switch(const WCHAR *s, const WCHAR c)
|
BOOL is_switch(const WCHAR *s, const WCHAR c)
|
||||||
{
|
{
|
||||||
if (lstrlenW(s) > 2)
|
if (lstrlenW(s) > 2)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ((s[0] == '/' || s[0] == '-') && (s[1] == c || s[1] == towupper(c)))
|
return ((s[0] == '/' || s[0] == '-') && is_char(s[1], c));
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL is_help_switch(const WCHAR *s)
|
static BOOL is_help_switch(const WCHAR *s)
|
||||||
|
|
|
@ -40,6 +40,7 @@ BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info);
|
||||||
HKEY path_get_rootkey(const WCHAR *path);
|
HKEY path_get_rootkey(const WCHAR *path);
|
||||||
WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len);
|
WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len);
|
||||||
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key);
|
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key);
|
||||||
|
BOOL is_char(const WCHAR s, const WCHAR c);
|
||||||
BOOL is_switch(const WCHAR *s, const WCHAR c);
|
BOOL is_switch(const WCHAR *s, const WCHAR c);
|
||||||
|
|
||||||
/* add.c */
|
/* add.c */
|
||||||
|
|
Loading…
Reference in New Issue