From 29df8c837a851934d0df31bd5362d34379129178 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Mon, 7 Feb 2022 13:15:01 +0000 Subject: [PATCH] SDV: NullCheck rule Check memory allocation succeeds. Also check RtlUnicodeStringToAnsiString succeeds, though this failure is unlikely when the buffer is pre-allocated. Signed-off-by: Owen Smith --- src/common/registry.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/registry.c b/src/common/registry.c index 9f5628c..b9b56e1 100644 --- a/src/common/registry.c +++ b/src/common/registry.c @@ -641,8 +641,15 @@ RegistryEnumerateValues( Ansi.MaximumLength = (USHORT)((Basic->NameLength / sizeof (WCHAR)) + sizeof (CHAR)); Ansi.Buffer = __RegistryAllocate(Ansi.MaximumLength); + status = STATUS_NO_MEMORY; + if (Ansi.Buffer == NULL) + goto fail6; + status = RtlUnicodeStringToAnsiString(&Ansi, &Unicode, FALSE); - ASSERT(NT_SUCCESS(status)); + if (!NT_SUCCESS(status)) { + __RegistryFree(Ansi.Buffer); + goto fail7; + } Ansi.Length = (USHORT)(strlen(Ansi.Buffer) * sizeof (CHAR)); @@ -651,7 +658,7 @@ RegistryEnumerateValues( __RegistryFree(Ansi.Buffer); if (!NT_SUCCESS(status)) - goto fail6; + goto fail8; } __RegistryFree(Basic); @@ -660,6 +667,8 @@ RegistryEnumerateValues( return STATUS_SUCCESS; +fail8: +fail7: fail6: fail5: __RegistryFree(Basic); -- 2.39.5