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:
Hugh McMaster 2021-04-01 23:20:48 +11:00 committed by Alexandre Julliard
parent 1b746c1e1c
commit 4df5c1641e
3 changed files with 24 additions and 15 deletions

View File

@ -344,27 +344,33 @@ static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
return hFile;
}
static BOOL is_overwrite_switch(const WCHAR *s)
{
return is_switch(s, 'y');
}
int reg_export(int argc, WCHAR *argvW[])
{
HKEY root, hkey;
WCHAR *path, *long_key;
BOOL overwrite_file = FALSE;
HANDLE hFile;
int ret;
int i, ret;
if (argc == 3 || argc > 5)
goto error;
if (argc < 4) goto invalid;
if (!parse_registry_key(argvW[2], &root, &path, &long_key))
return 1;
if (argc == 5 && !(overwrite_file = is_overwrite_switch(argvW[4])))
goto error;
for (i = 4; i < argc; i++)
{
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))
{
@ -382,7 +388,7 @@ int reg_export(int argc, WCHAR *argvW[])
return ret;
error:
invalid:
output_message(STRING_INVALID_SYNTAX);
output_message(STRING_FUNC_HELP, wcsupr(argvW[1]));
return 1;

View File

@ -250,15 +250,17 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long
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)
{
if (lstrlenW(s) > 2)
return FALSE;
if ((s[0] == '/' || s[0] == '-') && (s[1] == c || s[1] == towupper(c)))
return TRUE;
return FALSE;
return ((s[0] == '/' || s[0] == '-') && is_char(s[1], c));
}
static BOOL is_help_switch(const WCHAR *s)

View File

@ -40,6 +40,7 @@ BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info);
HKEY path_get_rootkey(const WCHAR *path);
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 is_char(const WCHAR s, const WCHAR c);
BOOL is_switch(const WCHAR *s, const WCHAR c);
/* add.c */