From efa6591fff772c7fc88f3dd26500610f55d6b551 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 28 Mar 2007 01:53:57 -0500 Subject: [PATCH] setupapi: Don't allow relative paths in SetupCopyOEMInf. --- dlls/setupapi/misc.c | 7 +++++++ dlls/setupapi/tests/misc.c | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index b1845b7e5c1..825782856db 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -944,6 +944,13 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location, return FALSE; } + /* check for a relative path */ + if (!(*source == '\\' || (*source && source[1] == ':'))) + { + SetLastError(ERROR_FILE_NOT_FOUND); + return FALSE; + } + if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE; strcatW( target, inf_oem ); diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c index cee48233111..ea11a6cfd38 100644 --- a/dlls/setupapi/tests/misc.c +++ b/dlls/setupapi/tests/misc.c @@ -118,16 +118,22 @@ static void test_SetupCopyOEMInf(void) SetLastError(0xdeadbeef); res = SetupCopyOEMInf("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); - todo_wine - { - ok(GetLastError() == ERROR_FILE_NOT_FOUND, - "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); - } + ok(GetLastError() == ERROR_FILE_NOT_FOUND, + "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); - /* try nonexistent SourceInfFileName */ + /* try a relative nonexistent SourceInfFileName */ SetLastError(0xdeadbeef); res = SetupCopyOEMInf("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); + ok(GetLastError() == ERROR_FILE_NOT_FOUND, + "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); + + /* try an absolute nonexistent SourceInfFileName */ + lstrcpy(path, CURR_DIR); + lstrcat(path, "\\nonexistent"); + SetLastError(0xdeadbeef); + res = SetupCopyOEMInf(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + ok(res == FALSE, "Expected FALSE, got %d\n", res); todo_wine { ok(GetLastError() == ERROR_FILE_NOT_FOUND, @@ -140,11 +146,8 @@ static void test_SetupCopyOEMInf(void) SetLastError(0xdeadbeef); res = SetupCopyOEMInf(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); - todo_wine - { - ok(GetLastError() == ERROR_FILE_NOT_FOUND, - "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); - } + ok(GetLastError() == ERROR_FILE_NOT_FOUND, + "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); get_temp_filename(tmpfile); create_inf_file(tmpfile); @@ -153,11 +156,8 @@ static void test_SetupCopyOEMInf(void) SetLastError(0xdeadbeef); res = SetupCopyOEMInf(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); - todo_wine - { - ok(GetLastError() == ERROR_FILE_NOT_FOUND, - "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); - } + ok(GetLastError() == ERROR_FILE_NOT_FOUND, + "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); ok(file_exists(tmpfile), "Expected tmpfile to exist\n"); /* try SP_COPY_REPLACEONLY, dest does not exist */ -- 2.11.4.GIT