]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
SDV: NullCheck rule
authorOwen Smith <owen.smith@citrix.com>
Mon, 7 Feb 2022 13:15:01 +0000 (13:15 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Wed, 16 Feb 2022 10:19:02 +0000 (10:19 +0000)
Check memory allocation succeeds.
Also check RtlUnicodeStringToAnsiString succeeds, though this failure is
unlikely when the buffer is pre-allocated.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
src/common/registry.c

index 9f5628cd559ea929edf2ae1d3d54104de3bf9b6f..b9b56e195a9f9f4c93f5ca26d961340ee5260883 100644 (file)
@@ -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);