From e94c1ce3aea2f3ccf7468a2ea5aed82df17b013b Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Mon, 2 Nov 2009 10:31:17 +0100 Subject: [PATCH] advapi32: Add some input parameter checks to OpenBackupEventLog. --- dlls/advapi32/eventlog.c | 36 ++++++++++++++++++++++++++++++---- dlls/advapi32/tests/eventlog.c | 12 ------------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/dlls/advapi32/eventlog.c b/dlls/advapi32/eventlog.c index f72dba94190..499011252ec 100644 --- a/dlls/advapi32/eventlog.c +++ b/dlls/advapi32/eventlog.c @@ -378,8 +378,16 @@ BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent ) */ HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName ) { - FIXME("(%s,%s) stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpFileName)); - return (HANDLE)0xcafe4242; + LPWSTR uncnameW, filenameW; + HANDLE handle; + + uncnameW = SERV_dup(lpUNCServerName); + filenameW = SERV_dup(lpFileName); + handle = OpenBackupEventLogW(uncnameW, filenameW); + HeapFree(GetProcessHeap(), 0, uncnameW); + HeapFree(GetProcessHeap(), 0, filenameW); + + return handle; } /****************************************************************************** @@ -389,8 +397,28 @@ HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName ) */ HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName ) { - FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName)); - return (HANDLE)0xcafe4242; + FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName)); + + if (!lpFileName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + if (lpUNCServerName && lpUNCServerName[0]) + { + FIXME("Remote server not supported\n"); + SetLastError(RPC_S_SERVER_UNAVAILABLE); + return NULL; + } + + if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES) + { + SetLastError(ERROR_FILE_NOT_FOUND); + return NULL; + } + + return (HANDLE)0xcafe4242; } /****************************************************************************** diff --git a/dlls/advapi32/tests/eventlog.c b/dlls/advapi32/tests/eventlog.c index 56df6d90e8c..8a96c691868 100644 --- a/dlls/advapi32/tests/eventlog.c +++ b/dlls/advapi32/tests/eventlog.c @@ -413,37 +413,25 @@ static void test_openbackup(void) SetLastError(0xdeadbeef); handle = OpenBackupEventLogA(NULL, NULL); - todo_wine - { ok(handle == NULL, "Didn't expect a handle\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); - } SetLastError(0xdeadbeef); handle = OpenBackupEventLogA(NULL, "idontexist.evt"); - todo_wine - { ok(handle == NULL, "Didn't expect a handle\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); - } SetLastError(0xdeadbeef); handle = OpenBackupEventLogA("IDontExist", NULL); - todo_wine - { ok(handle == NULL, "Didn't expect a handle\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); - } SetLastError(0xdeadbeef); handle = OpenBackupEventLogA("IDontExist", "idontexist.evt"); - todo_wine - { ok(handle == NULL, "Didn't expect a handle\n"); ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE || GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */ "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError()); - } /* Make a backup eventlog to work with */ DeleteFileA(backup);