Skip to content

Commit

Permalink
libfdt: fix an incorrect integer promotion
Browse files Browse the repository at this point in the history
UINT32_MAX is an integer of type unsigned int. UINT32_MAX + 1 overflows
unless explicitly computed as unsigned long long. This led to some
invalid addresses being treated as valid.

Cast UINT32_MAX to uint64_t explicitly.

Signed-off-by: Elvira Khabirova <[email protected]>
  • Loading branch information
Elvira Khabirova authored and dgibson committed Nov 17, 2021
1 parent 1cc41b1 commit c19a4ba
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libfdt/fdt_addresses.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
/* check validity of address */
prop = data;
if (addr_cells == 1) {
if ((addr > UINT32_MAX) || ((UINT32_MAX + 1 - addr) < size))
if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size))
return -FDT_ERR_BADVALUE;

fdt32_st(prop, (uint32_t)addr);
Expand Down

0 comments on commit c19a4ba

Please sign in to comment.