Fix up guid
GUIDs have some cases where they might not be representable as a string,
due to an overflow. To handle this previously, the existing
implementation just allocated extra space.
To ensure that we are always publishing correct guids, break this
function down into an add_guid method that we can call anytime we add a
guid to json. This function can use the appropriate guid string length,
and if we go over, we can make sure that we don't publish the string at
all, by handling the appropriate error codes.
Change-Id: I98239b7d5ba7567cea1b016579d7566e292b6e81
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/sections/cper-section-firmware.c b/sections/cper-section-firmware.c
index 78f04d0..327d70b 100644
--- a/sections/cper-section-firmware.c
+++ b/sections/cper-section-firmware.c
@@ -35,10 +35,7 @@
json_object_new_uint64(firmware_error->RecordId));
//Record GUID.
- char record_id_guid[GUID_STRING_LENGTH];
- guid_to_string(record_id_guid, &firmware_error->RecordIdGuid);
- json_object_object_add(section_ir, "recordIDGUID",
- json_object_new_string(record_id_guid));
+ add_guid(section_ir, "recordIDGUID", &firmware_error->RecordIdGuid);
return section_ir;
}
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index c127e93..c04bed1 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -148,13 +148,10 @@
EFI_IA32_X64_PROCESS_ERROR_INFO *error_info)
{
json_object *error_info_ir = json_object_new_object();
+ json_object *type = json_object_new_object();
//Error structure type (as GUID).
- char error_type[GUID_STRING_LENGTH];
- guid_to_string(error_type, &error_info->ErrorType);
- json_object *type = json_object_new_object();
- json_object_object_add(type, "guid",
- json_object_new_string(error_type));
+ add_guid(type, "guid", &error_info->ErrorType);
//Get the error structure type as a readable string.
const char *readable_type = "Unknown";