Detlef Riekenberg : netapi32: Avoid NULL access in
NetApiBufferAllocate, with test.
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Sep 8 10:24:50 CDT 2006
Module: wine
Branch: master
Commit: c8d441306893fec831ae0872e5297337adb25459
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=c8d441306893fec831ae0872e5297337adb25459
Author: Detlef Riekenberg <wine.dev at web.de>
Date: Fri Sep 8 11:29:54 2006 +0200
netapi32: Avoid NULL access in NetApiBufferAllocate, with test.
---
dlls/netapi32/apibuf.c | 2 ++
dlls/netapi32/tests/apibuf.c | 15 +++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/dlls/netapi32/apibuf.c b/dlls/netapi32/apibuf.c
index 87af683..136e9d7 100644
--- a/dlls/netapi32/apibuf.c
+++ b/dlls/netapi32/apibuf.c
@@ -36,6 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID* Buffer)
{
TRACE("(%ld, %p)\n", ByteCount, Buffer);
+
+ if (Buffer == NULL) return ERROR_INVALID_PARAMETER;
*Buffer = HeapAlloc(GetProcessHeap(), 0, ByteCount);
if (*Buffer)
return NERR_Success;
diff --git a/dlls/netapi32/tests/apibuf.c b/dlls/netapi32/tests/apibuf.c
index 91af3d4..871a4d3 100644
--- a/dlls/netapi32/tests/apibuf.c
+++ b/dlls/netapi32/tests/apibuf.c
@@ -39,6 +39,7 @@ static void run_apibuf_tests(void)
{
VOID *p;
DWORD dwSize;
+ NET_API_STATUS res;
if (!pNetApiBufferAllocate)
return;
@@ -76,6 +77,20 @@ static void run_apibuf_tests(void)
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer\n");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
+
+ /* NULL-Pointer */
+ /* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
+ SetLastError(0xdeadbeef);
+ res = pNetApiBufferAllocate(0, (LPVOID *)NULL);
+ ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
+ "returned %ld with 0x%lx (expected ERROR_INVALID_PARAMETER with " \
+ "0xdeadbeef)\n", res, GetLastError());
+
+ SetLastError(0xdeadbeef);
+ res = pNetApiBufferAllocate(1024, (LPVOID *)NULL);
+ ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
+ "returned %ld with 0x%lx (expected ERROR_INVALID_PARAMETER with " \
+ "0xdeadbeef)\n", res, GetLastError());
}
START_TEST(apibuf)
More information about the wine-cvs
mailing list