From: Vijay Kiran Kamuju infyquest@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47152 --- programs/schtasks/schtasks.c | 33 +++++++++++++++++++++++++++--- programs/schtasks/tests/schtasks.c | 17 ++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/programs/schtasks/schtasks.c b/programs/schtasks/schtasks.c index 7fc94205dac..3cecb9f8953 100644 --- a/programs/schtasks/schtasks.c +++ b/programs/schtasks/schtasks.c @@ -132,16 +132,32 @@ static BSTR read_file_to_bstr(const WCHAR *file_name) return ret; }
-static int search_option(WCHAR *option, hash_args inputs[], int icount) +static int search_str(WCHAR *option, const WCHAR **strlist, int count) { int i; - for (i = 0; i < icount; i++) { - if (!wcsicmp(option, inputs[i].option)) + + for (i = 0; i < count; i++) { + if (!wcsicmp(option, strlist[i])) return i; } + return -1; }
+static int search_option(WCHAR *option, hash_args inputs[], int icount) +{ + int i, ret; + const WCHAR **optlist; + + optlist = malloc(icount * sizeof(WCHAR *)); + for (i = 0; i < icount; i++) + optlist[i] = wcsdup(inputs[i].option); + ret = search_str(option, optlist, icount); + free(optlist); + + return ret; +} + static BOOL check_args(int argc, WCHAR *argv[], hash_args inputs[], int icount) { int index; @@ -216,6 +232,10 @@ static int change_command(int argc, WCHAR *argv[])
static int create_command(int argc, WCHAR *argv[]) { + static const WCHAR *sc_values[] = { L"minute", L"hourly", L"daily", + L"weekly", L"monthly", L"once", + L"onstart", L"onlogon", L"onidle", + L"onevent" }; hash_args create_args[7] = { {L"/tn", TRUE, FALSE}, {L"/xml", TRUE, FALSE}, {L"/f", TRUE, TRUE}, @@ -274,6 +294,7 @@ static int create_command(int argc, WCHAR *argv[]) ERR("/xml option can only be used with /ru /f /tn\n"); return E_FAIL; } + if (!create_args[3].value) { ERR("Missing /tr argument\n"); return E_FAIL; @@ -282,9 +303,15 @@ static int create_command(int argc, WCHAR *argv[]) ERR("Missing /sc argument\n"); return E_FAIL; } + + if (search_str(create_args[4].value, sc_values, 10) == -1) { + ERR("Invalid schedule type %s\n", debugstr_w(create_args[4].value)); + return E_FAIL; + } } return 0; } + return E_FAIL; }
diff --git a/programs/schtasks/tests/schtasks.c b/programs/schtasks/tests/schtasks.c index 35900a641f5..6f7203f21c2 100644 --- a/programs/schtasks/tests/schtasks.c +++ b/programs/schtasks/tests/schtasks.c @@ -238,7 +238,12 @@ START_TEST(schtasks) { "/delete /f /tn /tn wine\test\winetest", 1 }, { "/delete /f /tn wine\test\winetest", 0 }, { "/Change /tn wine\test\winetest /enable", 1 }, - { "/create /xml test.xml /tn wine\winetest", 0 }, + { "/create /xml test.xml", E_FAIL }, + { "/create /xml test.xml /tn", E_FAIL }, + { "/create /xml /tn wine\winetest", E_FAIL }, + { "/create /xml noexist.xml /tn wine\winetest", 1 }, + { "/create /xml empty.xml /tn wine\winetest", 1 }, + { "/create /xml test.xml /tn wine\winetest", 0 }, { "/create /xml test.xml /tn wine\winetest /tn", E_FAIL }, { "/create /xml test.xml /tn wine\winetest /xml", E_FAIL }, { "/create /xml test.xml /tn wine\winetest /tn test", E_FAIL }, @@ -249,9 +254,10 @@ START_TEST(schtasks) { "/create /xml test.xml /tn wine\winetest", 1 }, { "/create /xml test.xml /f /tn wine\winetest /tr c:\windows\hh.exe", E_FAIL }, { "/Delete /f /tn wine\winetest", 0 }, + { "/create /tn", E_FAIL }, { "/create /tn wine\winetest", E_FAIL }, - { "/create /tn wine\winetest /tr c:\windows\hh.exe", E_FAIL, FALSE }, - { "/create /tn wine\winetest /tr c:\windows\hh.exe /sc wine", E_FAIL, TRUE }, + { "/create /tn wine\winetest /tr c:\windows\hh.exe", E_FAIL }, + { "/create /tn wine\winetest /tr c:\windows\hh.exe /sc wine", E_FAIL }, { "/create /tn wine\winetest /tr c:\windows\hh.exe /sc daily", 0 }, { "/DELETE /f /tn wine\winetest", 0, TRUE } }; static WCHAR wineW[] = L"\wine"; @@ -272,6 +278,8 @@ START_TEST(schtasks)
create_file("test.xml", xml_a);
+ create_file("empty.xml", ""); + run_command_list(querylist, ARRAY_SIZE(querylist));
register_task("winetest"); @@ -286,6 +294,9 @@ START_TEST(schtasks)
run_command_list(creatlist, ARRAY_SIZE(creatlist));
+ r = DeleteFileA("empty.xml"); + ok(r, "DeleteFileA failed: %lu\n", GetLastError()); + r = DeleteFileA("test.xml"); ok(r, "DeleteFileA failed: %lu\n", GetLastError());