[rtems commit] libfdt: fix an incorrect integer promotion

Sebastian Huber sebh at rtems.org
Thu Dec 16 13:58:33 UTC 2021


Module:    rtems
Branch:    master
Commit:    8b21a1b9b2f9862ef4774ce3c27f87628cce8264
Changeset: http://git.rtems.org/rtems/commit/?id=8b21a1b9b2f9862ef4774ce3c27f87628cce8264

Author:    Elvira Khabirova <e.khabirova at omp.ru>
Date:      Tue Nov  9 18:47:19 2021 +0300

libfdt: fix an incorrect integer promotion

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 <e.khabirova at omp.ru>

---

 cpukit/dtc/libfdt/fdt_addresses.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/dtc/libfdt/fdt_addresses.c b/cpukit/dtc/libfdt/fdt_addresses.c
index 9a82cd0..c40ba09 100644
--- a/cpukit/dtc/libfdt/fdt_addresses.c
+++ b/cpukit/dtc/libfdt/fdt_addresses.c
@@ -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);



More information about the vc mailing list