Skip to content

Commit

Permalink
RedfishPkg/JsonLib: fix JsonObjectGetValue issue
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
Reviewed-by: Igor Kulchytskyy <[email protected]>
Reviewed-by: Abner Chang <[email protected]>
  • Loading branch information
nicklela authored and mergify[bot] committed Sep 22, 2023
1 parent ea628f2 commit f67e193
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions RedfishPkg/Library/JsonLib/JsonLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions RedfishPkg/Library/JsonLib/JsonLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f67e193

Please sign in to comment.