fix null pointer check in grub_acpi_create_ebda
PATCH 1/1 fix null pointer check in grub_acpi_create_ebda
The current code in grub_acpi_create_ebda() first computes the ebda pointer, then dereferences it, and then checks whether the ebda pointer was null. Several compilers (including gcc) will eliminate null pointer checks after the pointer has been dereferenced, on the assumption that the pointer could not be null, since it has already been dereferenced. The patch below ensures that ebda is dereferenced only if it is non-null.
Nickolai.
---
commands/acpi.c +4 -3
@@ -171,7 +171,7 @@struct grub_acpi_create_ebda_ctx ctx = { .highestlow =0 }; -int ebda_kb_len; +int ebda_kb_len =0 ;int mmapregion =0 ;grub_uint8_t *ebda, *v1inebda =0 , *v2inebda =0 ;grub_uint8_t *targetebda, *target;
@@ -179,8 +179,9 @@struct grub_acpi_rsdp_v20 *v2; ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)0x40e )) <<4 ); - ebda_kb_len = *(grub_uint16_t *) ebda; -if (! ebda || ebda_kb_len >16 ) +if (ebda) + ebda_kb_len = *(grub_uint16_t *) ebda; +if (ebda_kb_len >16 ) ebda_kb_len =0 ; ctx.ebda_len = (ebda_kb_len +1 ) <<10 ;