[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/4] SDV: NullCheck rule


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Durrant, Paul" <xadimgnik@xxxxxxxxx>
  • Date: Fri, 11 Feb 2022 19:54:35 +0000
  • Delivery-date: Fri, 11 Feb 2022 19:54:40 +0000
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

On 07/02/2022 13:15, Owen Smith wrote:
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@xxxxxxxxxx>

Reviewed-by: Paul Durrant <paul@xxxxxxx>

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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.