Fix IA32x64 pointer corruption, invalid generation on ARM.
diff --git a/README.md b/README.md
index 9a6af67..df736ee 100644
--- a/README.md
+++ b/README.md
@@ -33,5 +33,4 @@
### Remaining Task List
- Add readable versions of the IA32/x64 processor info type GUIDs, updating specification & both conversions.
-- Add remaining `cper-generate` sections for testing purposes.
- Add a top-level "specification" object which indicates which version/revision of the specification the JSON is using.
\ No newline at end of file
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 85d49cd..7e7cc40 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -112,7 +112,7 @@
//Ensure the FRU text is not null terminated early.
for (int i=0; i<20; i++)
{
- if (descriptor->FruString[i] = 0x0)
+ if (descriptor->FruString[i] == 0x0)
descriptor->FruString[i] = rand() % 127 + 1;
//Null terminate last byte.
diff --git a/generator/sections/gen-section-arm.c b/generator/sections/gen-section-arm.c
index 53fb24c..bce04c5 100644
--- a/generator/sections/gen-section-arm.c
+++ b/generator/sections/gen-section-arm.c
@@ -52,6 +52,10 @@
*(section + 12) = rand() % 4;
//Reserved zero bytes.
+ UINT64* validation = (UINT64*)section;
+ *validation &= 0b111;
+ UINT32* running_state = (UINT32*)(section + 32);
+ *running_state &= 0b1;
memset(section + 13, 0, 3);
//Copy in the sections/context structures, free resources.
@@ -87,6 +91,10 @@
UINT8 error_type = rand() % 4;
*(error_info + 4) = error_type;
+ //Reserved bits for error information.
+ UINT16* validation = (UINT16*)(error_info + 2);
+ *validation &= 0x1F;
+
//Make sure reserved bits are zero according with the type.
UINT64* error_subinfo = (UINT64*)(error_info + 8);
switch (error_type)
diff --git a/generator/sections/gen-section-ia32x64.c b/generator/sections/gen-section-ia32x64.c
index 0f6f709..2fb6585 100644
--- a/generator/sections/gen-section-ia32x64.c
+++ b/generator/sections/gen-section-ia32x64.c
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "../../edk/Cper.h"
#include "../gen-utils.h"
#include "gen-sections.h"
@@ -114,7 +115,7 @@
memcpy(guid, &gEfiIa32x64ErrorTypeMsCheckGuid, sizeof(EFI_GUID));
//Set reserved space to zero.
- *check_info &= ~0xFF30;
+ *check_info &= ~0xFFE0;
*check_info &= 0xFFFFFF;
break;
}
@@ -135,7 +136,7 @@
if (reg_type == 3)
reg_size = 244; //x64 registers.
else
- reg_size = rand() % 64; //Not table defined.
+ reg_size = (rand() % 5) * 32; //Not table defined.
//Create structure randomly.
int total_size = 16 + reg_size;
@@ -144,6 +145,7 @@
//Set header information.
*(context_structure) = reg_type;
*(context_structure + 1) = reg_size;
+ printf("set reg size to %d (for type %d).\n", reg_size, reg_type);
//Set return values and exit.
*location = context_structure;
diff --git a/sections/cper-section-arm.c b/sections/cper-section-arm.c
index c52da3e..73e63ed 100644
--- a/sections/cper-section-arm.c
+++ b/sections/cper-section-arm.c
@@ -61,7 +61,7 @@
//Whether the processor is running, and the state of it if so.
json_object_object_add(section_ir, "running", json_object_new_boolean(record->RunningState & 0b1));
- if (record->RunningState >> 31)
+ if (!(record->RunningState >> 31))
{
//Bit 32 of running state is on, so PSCI state information is included.
//This can't be made human readable, as it is unknown whether this will be the pre-PSCI 1.0 format
@@ -360,6 +360,7 @@
void ir_section_arm_to_cper(json_object* section, FILE* out)
{
EFI_ARM_ERROR_RECORD* section_cper = (EFI_ARM_ERROR_RECORD*)calloc(1, sizeof(EFI_ARM_ERROR_RECORD));
+ long starting_stream_pos = ftell(out);
//Validation bits.
section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
@@ -399,9 +400,13 @@
json_object* vendor_specific_info = json_object_object_get(section, "vendorSpecificInfo");
if (vendor_specific_info != NULL)
{
- int vendor_specific_len = json_object_get_string_len(vendor_specific_info);
- UINT8* decoded = b64_decode(json_object_get_string(vendor_specific_info), vendor_specific_len);
- fwrite(decoded, vendor_specific_len / 4 * 3, 1, out); //b64 length to byte length
+ json_object* vendor_info_string = json_object_object_get(vendor_specific_info, "data");
+ int vendor_specific_len = json_object_get_string_len(vendor_info_string);
+ UINT8* decoded = b64_decode(json_object_get_string(vendor_info_string), vendor_specific_len);
+
+ //Write out to file.
+ long cur_stream_pos = ftell(out);
+ fwrite(decoded, starting_stream_pos + section_cper->SectionLength - cur_stream_pos, 1, out);
fflush(out);
free(decoded);
}
diff --git a/sections/cper-section-dmar-generic.h b/sections/cper-section-dmar-generic.h
index 14b65a9..634339a 100644
--- a/sections/cper-section-dmar-generic.h
+++ b/sections/cper-section-dmar-generic.h
@@ -10,7 +10,8 @@
"Invalid Device Request", "ATT Access Error", "ATT Reserved Bit Invalid", "Illegal Command", "Command Buffer Access Error"}
#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS (const char*[]){ \
"Domain mapping table entry is not present.", \
- "DMAr unit's attempt to access the domain mapping table resulted in an error." \
+ "Invalid domain mapping table entry.", \
+ "DMAr unit's attempt to access the domain mapping table resulted in an error.", \
"Reserved bit set to non-zero value in the domain mapping table.", \
"DMA request to access an address beyond the device address width.", \
"Invalid read or write access.", \
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index 9e79888..5102a33 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -72,10 +72,12 @@
//Processor context information, of the amount described above.
EFI_IA32_X64_PROCESSOR_CONTEXT_INFO* current_context_info = (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO*)current_error_info;
+ void* cur_pos = (void*)current_context_info;
json_object* context_info_array = json_object_new_array();
for (int i=0; i<processor_context_info_num; i++)
{
- json_object_array_add(context_info_array, cper_ia32x64_processor_context_info_to_ir(current_context_info, (void**)¤t_context_info));
+ json_object_array_add(context_info_array, cper_ia32x64_processor_context_info_to_ir(current_context_info, &cur_pos));
+ current_context_info = (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO*)cur_pos;
//The context array is a non-fixed size, pointer is shifted within the above function.
}
json_object_object_add(record_ir, "processorContextInfo", context_info_array);