Fix parsing single section CPER error
Single section CPER logs do not contain a Record Header. The check for
a valid header is now performed only if the content includes a Record
Header. Additionally, this update fixes an issue with the size
calculation for single-section logs.
Tested :
$> ./cper-generate --out single-cper.file --single-section firmware
$> ./cper-convert to-json-section single-cper.file
Change-Id: Id7efec20df3e5b53c6f90330e0770c1f682a8d87
Signed-off-by: John Chung <john.chung@arm.com>
diff --git a/cper-parse.c b/cper-parse.c
index 27cfd72..b91a54e 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -414,6 +414,7 @@
json_object *section_ir =
definition->ToIR(cper_section_buf, size, &cper_description);
if (section_ir == NULL) {
+ free(cper_description);
return NULL;
}
json_object *result = json_object_new_object();
@@ -527,7 +528,7 @@
json_object_object_add(ir, "sectionDescriptor", section_descriptor_ir);
section_begin = cper_buf + section_descriptor->SectionOffset;
- if (section_begin + section_descriptor->SectionLength >= cper_end) {
+ if (section_begin + section_descriptor->SectionLength > cper_end) {
json_object_put(ir);
//cper_print_log("Invalid CPER file: Invalid section descriptor (section offset + length > size).\n");
return NULL;