Make sections return known values
Some sections when being fuzzed might not return valid values. Make
sure behavior is consistent.
Change-Id: I5c334acd2208872a48a8a9f887317a5066cd4422
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/cper-parse.c b/cper-parse.c
index ccd863f..2cfe71c 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -116,6 +116,7 @@
cper_buf + section_descriptor->SectionOffset;
json_object *section_descriptor_ir =
cper_section_descriptor_to_ir(section_descriptor);
+
json_object_array_add(section_descriptors_ir,
section_descriptor_ir);
@@ -123,10 +124,6 @@
json_object *section_ir = cper_buf_section_to_ir(
section_begin, section_descriptor->SectionLength,
section_descriptor);
- if (section_ir == NULL) {
- cper_print_log("Failed to parse section %d\n", i);
- section_ir = json_object_new_object();
- }
json_object_array_add(sections_ir, section_ir);
}
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index 2206d2a..85f03a4 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -134,9 +134,6 @@
cper_ia32x64_processor_context_info_to_ir(
current_context_info, &cur_pos,
&remaining_size);
- if (context_info == NULL) {
- context_info = json_object_new_object();
- }
json_object_array_add(context_info_array, context_info);
current_context_info =
(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *)cur_pos;
@@ -221,9 +218,10 @@
"WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
break;
}
-
- json_object_object_add(error_info_ir, "checkInfo",
- check_information);
+ if (check_information != NULL) {
+ json_object_object_add(error_info_ir, "checkInfo",
+ check_information);
+ }
}
//Target, requestor, and responder identifiers.
@@ -470,12 +468,11 @@
EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *context_info, void **cur_pos,
UINT32 *remaining_size)
{
- json_object *context_info_ir = json_object_new_object();
-
if (*remaining_size < sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO)) {
- return context_info_ir;
+ return NULL;
}
*remaining_size -= sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO);
+ json_object *context_info_ir = json_object_new_object();
//Register context type.
json_object *context_type = integer_to_readable_pair(
@@ -542,8 +539,10 @@
(void *)(((char *)*cur_pos) + context_info->ArraySize);
*remaining_size -= context_info->ArraySize;
}
- json_object_object_add(context_info_ir, "registerArray",
- register_array);
+ if (register_array != NULL) {
+ json_object_object_add(context_info_ir, "registerArray",
+ register_array);
+ }
return context_info_ir;
}