Check and see if JSON object type is desired type before
getting its value. According to the Redfish schema, attribute
value can be null value. Add this error handling to avoid
system assertion while getting attribute value.

Signed-off-by: Nickle Wang <nick...@nvidia.com>
Cc: Abner Chang <abner.ch...@amd.com>
Cc: Igor Kulchytskyy <ig...@ami.com>
Cc: Nick Ramirez <nrami...@nvidia.com>
---
 RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c 
b/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c
index 250ef75e4..7ee3c86e1 100644
--- a/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c
+++ b/RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c
@@ -1,5 +1,7 @@
 /** @file
 
+  Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
   Copyright Notice:
   Copyright 2019-2024 Distributed Management Task Force, Inc. All rights 
reserved.
   License: BSD 3-Clause License. For full text see link: 
https://github.com/DMTF/Redfish-JSON-C-Struct-Converter/blob/master/LICENSE.md
@@ -829,6 +831,10 @@ GetRedfishPropertyStr (
     return RedfishCS_status_not_found;
   }
 
+  if (!json_is_string (TempJsonObj)) {
+    return RedfishCS_status_not_found;
+  }
+
   Status = allocateDuplicateStr (Cs, (char *)json_string_value (TempJsonObj), 
(void **)DstBuffer);
   return Status;
 }
@@ -914,6 +920,10 @@ GetRedfishPropertyInt64 (
     return Status;
   }
 
+  if (!json_is_integer (TempJsonObj)) {
+    return RedfishCS_status_not_found;
+  }
+
   **Dst = (RedfishCS_int64)json_integer_value (TempJsonObj);
   return RedfishCS_status_success;
 }
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116040): https://edk2.groups.io/g/devel/message/116040
Mute This Topic: https://groups.io/mt/104601599/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to