From 0d763e60fbc47e5ca5e861699ce629ac5f63fa5c Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sun, 24 May 2015 17:31:49 +0000 Subject: [PATCH] [KMTEST] Don't attempt to allocate null-size buffer when copying empty string. Note to next generations students: test your code and DON'T LEAK MEMORY!!!! It still leaks atm, will have a look later on. Note to Mr Bragin, beloved ReactOS Project Coordinator: did you actually reviewed your students work? CORE-7272 svn path=/trunk/; revision=67885 --- rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c b/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c index 1097807a839..b8894117640 100644 --- a/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c +++ b/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c @@ -33,9 +33,16 @@ PUNICODE_STRING CopyUS(PUNICODE_STRING a) ok(b != NULL, "US is NULL after allocated memory\n"); b->Length = 0; b->MaximumLength =a->MaximumLength; - b->Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, b->MaximumLength, 1633); - ok(b->Buffer != NULL, "US->Buffer is NULL after allocated memory\n"); - RtlCopyUnicodeString(b, a); + if (b->MaximumLength) + { + b->Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, b->MaximumLength, 1633); + ok(b->Buffer != NULL, "US->Buffer is NULL after allocated memory\n"); + RtlCopyUnicodeString(b, a); + } + else + { + b->Buffer = NULL; + } return b; } @@ -147,6 +154,7 @@ START_TEST(FsRtlTunnel) TestFsRtlAddToTunnelCache(12345, s_name, l_name, TRUE); TestFsRtlAddToTunnelCache(12347, s_name, l_name, TRUE); a = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING)); + RtlInitUnicodeString(a, NULL); TestFsRtlAddToTunnelCache(12346, a, l_name, FALSE); //Clear all