public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
@ 2023-09-21 12:56 Nickle Wang via groups.io
  2023-09-22  1:15 ` Chang, Abner via groups.io
  0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang via groups.io @ 2023-09-21 12:56 UTC (permalink / raw)
  To: devel; +Cc: Abner Chang, Igor Kulchytskyy, Nick Ramirez

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@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 RedfishPkg/Library/JsonLib/JsonLib.inf |  1 +
 RedfishPkg/Library/JsonLib/JsonLib.c   | 35 ++++++++++++++++++++++++++
 2 files changed, 36 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..6c3373d205c3 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,36 @@ 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. This fixed number will be removed after the protocol version
+  // of JsonLib is implemented in the future.
+  //
+  hashtable_seed = 0xFDAE2143;
+
+  return EFI_SUCCESS;
+}
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108942): https://edk2.groups.io/g/devel/message/108942
Mute This Topic: https://groups.io/mt/101499238/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
  2023-09-21 12:56 [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: fix JsonObjectGetValue issue Nickle Wang via groups.io
@ 2023-09-22  1:15 ` Chang, Abner via groups.io
  0 siblings, 0 replies; 2+ messages in thread
From: Chang, Abner via groups.io @ 2023-09-22  1:15 UTC (permalink / raw)
  To: Nickle Wang, devel@edk2.groups.io; +Cc: Igor Kulchytskyy, Nick Ramirez

[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Thursday, September 21, 2023 8:56 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
> Subject: [PATCH v2] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> 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@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  RedfishPkg/Library/JsonLib/JsonLib.inf |  1 +
>  RedfishPkg/Library/JsonLib/JsonLib.c   | 35
> ++++++++++++++++++++++++++
>  2 files changed, 36 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..6c3373d205c3 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,36 @@ 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. This fixed number will be removed after the protocol version
> +  // of JsonLib is implemented in the future.
> +  //
> +  hashtable_seed = 0xFDAE2143;
> +
> +  return EFI_SUCCESS;
> +}
> --
> 2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108973): https://edk2.groups.io/g/devel/message/108973
Mute This Topic: https://groups.io/mt/101499238/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-22  1:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21 12:56 [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: fix JsonObjectGetValue issue Nickle Wang via groups.io
2023-09-22  1:15 ` Chang, Abner via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox