netapi32: Avoid NULL access in NetApiBufferAllocate, with test.

This commit is contained in:
Detlef Riekenberg 2006-09-08 11:29:54 +02:00 committed by Alexandre Julliard
parent 4388bdac70
commit c8d4413068
2 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -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)