[edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue

Igor Kulchytskyy via groups.io igork=ami.com at groups.io
Mon Sep 18 13:41:30 UTC 2023


Hi Nickle,
Does that mean, that json_object_seed function is useless anymore with those changes?
And there is no need for other module to call json_object_seed?
Thank you,
Igor

-----Original Message-----
From: Nickle Wang <nicklew at nvidia.com>
Sent: Monday, September 18, 2023 9:09 AM
To: devel at edk2.groups.io
Cc: Abner Chang <abner.chang at amd.com>; Igor Kulchytskyy <igork at ami.com>; Nick Ramirez <nramirez at nvidia.com>
Subject: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue


**CAUTION: The e-mail below is from an external source. Please exercise caution before opening attachments, clicking links, or following guidance.**

JsonObjectGetValue() cannot find corresponding JSON value
when the EDKII_JSON_VALUE object is created by another UEFI
driver. This is because "hashtable_seed" is initialized by
current time while JsonLib is loaded. So, "hashtable_seed"
will be different in each individual UEFI driver.

Signed-off-by: Nickle Wang <nicklew at nvidia.com>
Cc: Abner Chang <abner.chang at amd.com>
Cc: Igor Kulchytskyy <igork at ami.com>
Cc: Nick Ramirez <nramirez at nvidia.com>
---
 RedfishPkg/Library/JsonLib/JsonLib.inf |  1 +
 RedfishPkg/Library/JsonLib/JsonLib.c   | 34 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/RedfishPkg/Library/JsonLib/JsonLib.inf b/RedfishPkg/Library/JsonLib/JsonLib.inf
index 9d52a622e13a..b0d1bcac7cb3 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.inf
+++ b/RedfishPkg/Library/JsonLib/JsonLib.inf
@@ -15,6 +15,7 @@
   MODULE_TYPE                    = DXE_DRIVER
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = JsonLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER
+  CONSTRUCTOR                    = JsonLibConstructor

 #
 #  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64 RISCV64
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index 9b758b940293..a7ec2ab217a6 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -19,6 +19,8 @@

 #include "jansson.h"

+extern volatile UINT32  hashtable_seed;
+
 /**
   The function is used to initialize a JSON value which contains a new JSON array,
   or NULL on error. Initially, the array is empty.
@@ -1138,3 +1140,35 @@ JsonGetType (
 {
   return (EDKII_JSON_TYPE)(((json_t *)JsonValue)->type);
 }
+
+/**
+  JSON Library constructor.
+
+  @param ImageHandle     The image handle.
+  @param SystemTable     The system table.
+
+  @retval  EFI_SUCCESS  Protocol listener is registered successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+JsonLibConstructor (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  //
+  // hashtable_seed is initalized by current time while JsonLib is loaded.
+  // Due to above mechanism, hashtable_seed will be different in each individual
+  // UEFI driver. As the result, the hash of same key in different UEFI driver
+  // would be different. This breaks JsonObjectGetValue() because
+  // JsonObjectGetValue() won't be able to find corresponding JSON value if
+  // this EDKII_JSON_VALUE is created by another UEFI driver.
+  //
+  // Initial the seed to a fixed magic value for JsonLib to be working in all
+  // UEFI drivers.
+  //
+  hashtable_seed = 0xFDAE2143;
+
+  return EFI_SUCCESS;
+}
--
2.17.1

-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108781): https://edk2.groups.io/g/devel/message/108781
Mute This Topic: https://groups.io/mt/101432663/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list