public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
@ 2023-09-18 13:08 Nickle Wang via groups.io
  2023-09-18 13:41 ` Igor Kulchytskyy via groups.io
  2023-09-20 15:19 ` Igor Kulchytskyy via groups.io
  0 siblings, 2 replies; 8+ messages in thread
From: Nickle Wang via groups.io @ 2023-09-18 13:08 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   | 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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108777): https://edk2.groups.io/g/devel/message/108777
Mute This Topic: https://groups.io/mt/101432663/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] 8+ messages in thread

* Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
  2023-09-18 13:08 [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue Nickle Wang via groups.io
@ 2023-09-18 13:41 ` Igor Kulchytskyy via groups.io
  2023-09-20  9:17   ` Nickle Wang via groups.io
  2023-09-20 15:19 ` Igor Kulchytskyy via groups.io
  1 sibling, 1 reply; 8+ messages in thread
From: Igor Kulchytskyy via groups.io @ 2023-09-18 13:41 UTC (permalink / raw)
  To: Nickle Wang, devel@edk2.groups.io; +Cc: Abner Chang, Nick Ramirez

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@nvidia.com>
Sent: Monday, September 18, 2023 9:09 AM
To: devel@edk2.groups.io
Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>; Nick Ramirez <nramirez@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@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   | 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/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] 8+ messages in thread

* Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
  2023-09-18 13:41 ` Igor Kulchytskyy via groups.io
@ 2023-09-20  9:17   ` Nickle Wang via groups.io
  2023-09-20 15:18     ` Igor Kulchytskyy via groups.io
  0 siblings, 1 reply; 8+ messages in thread
From: Nickle Wang via groups.io @ 2023-09-20  9:17 UTC (permalink / raw)
  To: Igor Kulchytskyy, devel@edk2.groups.io; +Cc: Abner Chang, Nick Ramirez

Hi Igor,

According to my understanding to jansson implementation, json_object_seed() is only called in three places. Two of them are in test code and we don't use them in EDK2. The only chance to call json_object_seed() is in json_object(). So, it is called when driver create new JSON object and hashtable_seed is not initialized yet, which means  json_object_seed() will be called only once per UEFI driver.

json_object_seed() use current time as hash table seed, which creates issue in EDK2 environment. In EDK2, library is built with UEFI driver together. So, there are multiple instances of JsonLib in the system. And the hash table seed is different in each driver in current implementation. As the result, the JSON object created by this driver can not be used by another driver.

> Does that mean, that json_object_seed function is useless anymore with those
> changes?

Yes, once constructor set hashtable_seed to a magic value, json_object_seed() won't do anything.

> And there is no need for other module to call json_object_seed?

No, it is called when driver create JSON object and the seed is still zero. Once the seed is set to non-zero value, json_object_seed() does nothing.

Regards,
Nickle

> -----Original Message-----
> From: Igor Kulchytskyy <igork@ami.com>
> Sent: Monday, September 18, 2023 9:42 PM
> To: Nickle Wang <nicklew@nvidia.com>; devel@edk2.groups.io
> Cc: Abner Chang <abner.chang@amd.com>; Nick Ramirez
> <nramirez@nvidia.com>
> Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue
> issue
> 
> External email: Use caution opening links or attachments
> 
> 
> 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@nvidia.com>
> Sent: Monday, September 18, 2023 9:09 AM
> To: devel@edk2.groups.io
> Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>;
> Nick Ramirez <nramirez@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@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   | 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 (#108904): https://edk2.groups.io/g/devel/message/108904
Mute This Topic: https://groups.io/mt/101432663/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

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

Hi Nickle,
Yes, I understand the mechanism of how seed works.
And when I used the RedfishPkg and Jansson parser in my modules, I passed the seed to each driver, so, all of them used the same seed.
All of them call a  json_object_seed() function with the same seed.
Now, there is no need to do it.
Thank you,
Igor

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

Hi Igor,

According to my understanding to jansson implementation, json_object_seed() is only called in three places. Two of them are in test code and we don't use them in EDK2. The only chance to call json_object_seed() is in json_object(). So, it is called when driver create new JSON object and hashtable_seed is not initialized yet, which means  json_object_seed() will be called only once per UEFI driver.

json_object_seed() use current time as hash table seed, which creates issue in EDK2 environment. In EDK2, library is built with UEFI driver together. So, there are multiple instances of JsonLib in the system. And the hash table seed is different in each driver in current implementation. As the result, the JSON object created by this driver can not be used by another driver.

> Does that mean, that json_object_seed function is useless anymore with those
> changes?

Yes, once constructor set hashtable_seed to a magic value, json_object_seed() won't do anything.

> And there is no need for other module to call json_object_seed?

No, it is called when driver create JSON object and the seed is still zero. Once the seed is set to non-zero value, json_object_seed() does nothing.

Regards,
Nickle

> -----Original Message-----
> From: Igor Kulchytskyy <igork@ami.com>
> Sent: Monday, September 18, 2023 9:42 PM
> To: Nickle Wang <nicklew@nvidia.com>; devel@edk2.groups.io
> Cc: Abner Chang <abner.chang@amd.com>; Nick Ramirez
> <nramirez@nvidia.com>
> Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue
> issue
>
> External email: Use caution opening links or attachments
>
>
> 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@nvidia.com>
> Sent: Monday, September 18, 2023 9:09 AM
> To: devel@edk2.groups.io
> Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>;
> Nick Ramirez <nramirez@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@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   | 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.
-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 (#108917): https://edk2.groups.io/g/devel/message/108917
Mute This Topic: https://groups.io/mt/101432663/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue
  2023-09-18 13:08 [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue Nickle Wang via groups.io
  2023-09-18 13:41 ` Igor Kulchytskyy via groups.io
@ 2023-09-20 15:19 ` Igor Kulchytskyy via groups.io
  2023-09-21  2:20   ` Chang, Abner via groups.io
  1 sibling, 1 reply; 8+ messages in thread
From: Igor Kulchytskyy via groups.io @ 2023-09-20 15:19 UTC (permalink / raw)
  To: Nickle Wang, devel@edk2.groups.io; +Cc: Abner Chang, Nick Ramirez

Reviewed-by: Igor Kulchytskyy <igork@ami.com>

Regards,
Igor
-----Original Message-----
From: Nickle Wang <nicklew@nvidia.com>
Sent: Monday, September 18, 2023 9:09 AM
To: devel@edk2.groups.io
Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>; Nick Ramirez <nramirez@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@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   | 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 (#108918): https://edk2.groups.io/g/devel/message/108918
Mute This Topic: https://groups.io/mt/101432663/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] 8+ messages in thread

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

[AMD Official Use Only - General]

Hi Nickle,
As we may use a protocol that provide the JSON interface for other packages or drivers, could you please have a comment around the hardcoded number says the hardcoded number would be removed when we have a protocol on top of jansson lib? People can still have the real hashtable seed if they use library directly.

Thanks
Abner

> -----Original Message-----
> From: Igor Kulchytskyy <igork@ami.com>
> Sent: Wednesday, September 20, 2023 11:19 PM
> To: Nickle Wang <nicklew@nvidia.com>; devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Nick Ramirez
> <nramirez@nvidia.com>
> Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue
> issue
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Reviewed-by: Igor Kulchytskyy <igork@ami.com>
>
> Regards,
> Igor
> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Monday, September 18, 2023 9:09 AM
> To: devel@edk2.groups.io
> Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; Nick Ramirez <nramirez@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@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   | 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 (#108930): https://edk2.groups.io/g/devel/message/108930
Mute This Topic: https://groups.io/mt/101432663/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

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

Hi Abner,

I add suggested comment in version 2: https://edk2.groups.io/g/devel/message/108942

Thanks,
Nickle

> -----Original Message-----
> From: Chang, Abner <Abner.Chang@amd.com>
> Sent: Thursday, September 21, 2023 10:20 AM
> To: Igor Kulchytskyy <igork@ami.com>; Nickle Wang <nicklew@nvidia.com>;
> devel@edk2.groups.io
> Cc: Nick Ramirez <nramirez@nvidia.com>
> Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue
> issue
> 
> External email: Use caution opening links or attachments
> 
> 
> [AMD Official Use Only - General]
> 
> Hi Nickle,
> As we may use a protocol that provide the JSON interface for other packages or
> drivers, could you please have a comment around the hardcoded number says the
> hardcoded number would be removed when we have a protocol on top of jansson
> lib? People can still have the real hashtable seed if they use library directly.
> 
> Thanks
> Abner
> 
> > -----Original Message-----
> > From: Igor Kulchytskyy <igork@ami.com>
> > Sent: Wednesday, September 20, 2023 11:19 PM
> > To: Nickle Wang <nicklew@nvidia.com>; devel@edk2.groups.io
> > Cc: Chang, Abner <Abner.Chang@amd.com>; Nick Ramirez
> > <nramirez@nvidia.com>
> > Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix
> > JsonObjectGetValue issue
> >
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> >
> >
> > Reviewed-by: Igor Kulchytskyy <igork@ami.com>
> >
> > Regards,
> > Igor
> > -----Original Message-----
> > From: Nickle Wang <nicklew@nvidia.com>
> > Sent: Monday, September 18, 2023 9:09 AM
> > To: devel@edk2.groups.io
> > Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy
> > <igork@ami.com>; Nick Ramirez <nramirez@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@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   | 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 (#108943): https://edk2.groups.io/g/devel/message/108943
Mute This Topic: https://groups.io/mt/101432663/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

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

[AMD Official Use Only - General]

Thank you Nickle. RB is given to that patch.

Abner

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Thursday, September 21, 2023 9:00 PM
> To: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; devel@edk2.groups.io
> Cc: Nick Ramirez <nramirez@nvidia.com>
> Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue
> issue
>
> [AMD Official Use Only - General]
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Hi Abner,
>
> I add suggested comment in version 2:
> https://edk2.groups.io/g/devel/message/108942
>
> Thanks,
> Nickle
>
> > -----Original Message-----
> > From: Chang, Abner <Abner.Chang@amd.com>
> > Sent: Thursday, September 21, 2023 10:20 AM
> > To: Igor Kulchytskyy <igork@ami.com>; Nickle Wang <nicklew@nvidia.com>;
> > devel@edk2.groups.io
> > Cc: Nick Ramirez <nramirez@nvidia.com>
> > Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix
> JsonObjectGetValue
> > issue
> >
> > External email: Use caution opening links or attachments
> >
> >
> > [AMD Official Use Only - General]
> >
> > Hi Nickle,
> > As we may use a protocol that provide the JSON interface for other packages
> or
> > drivers, could you please have a comment around the hardcoded number
> says the
> > hardcoded number would be removed when we have a protocol on top of
> jansson
> > lib? People can still have the real hashtable seed if they use library directly.
> >
> > Thanks
> > Abner
> >
> > > -----Original Message-----
> > > From: Igor Kulchytskyy <igork@ami.com>
> > > Sent: Wednesday, September 20, 2023 11:19 PM
> > > To: Nickle Wang <nicklew@nvidia.com>; devel@edk2.groups.io
> > > Cc: Chang, Abner <Abner.Chang@amd.com>; Nick Ramirez
> > > <nramirez@nvidia.com>
> > > Subject: RE: [EXTERNAL] [PATCH] RedfishPkg/JsonLib: fix
> > > JsonObjectGetValue issue
> > >
> > > Caution: This message originated from an External Source. Use proper
> > > caution when opening attachments, clicking links, or responding.
> > >
> > >
> > > Reviewed-by: Igor Kulchytskyy <igork@ami.com>
> > >
> > > Regards,
> > > Igor
> > > -----Original Message-----
> > > From: Nickle Wang <nicklew@nvidia.com>
> > > Sent: Monday, September 18, 2023 9:09 AM
> > > To: devel@edk2.groups.io
> > > Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy
> > > <igork@ami.com>; Nick Ramirez <nramirez@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@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   | 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 (#108974): https://edk2.groups.io/g/devel/message/108974
Mute This Topic: https://groups.io/mt/101432663/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-18 13:08 [edk2-devel] [PATCH] RedfishPkg/JsonLib: fix JsonObjectGetValue issue Nickle Wang via groups.io
2023-09-18 13:41 ` Igor Kulchytskyy via groups.io
2023-09-20  9:17   ` Nickle Wang via groups.io
2023-09-20 15:18     ` Igor Kulchytskyy via groups.io
2023-09-20 15:19 ` Igor Kulchytskyy via groups.io
2023-09-21  2:20   ` Chang, Abner via groups.io
2023-09-21 13:00     ` Nickle Wang via groups.io
2023-09-22  1:17       ` 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