Fix integer wrap sanitisation. am: 0e783e26f7
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/dtc/+/19430787
Change-Id: Ib059fe92ce104aef1ab4583f136e37d499823283
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index c28fcc1..3f9cf3e 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -176,12 +176,20 @@
break;
case FDT_PROP:
- lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
+ lenp = fdt_offset_ptr(fdt, offset, sizeof(struct fdt_property) - FDT_TAGSIZE);
if (!can_assume(VALID_DTB) && !lenp)
return FDT_END; /* premature end */
- /* skip-name offset, length and value */
- offset += sizeof(struct fdt_property) - FDT_TAGSIZE
- + fdt32_to_cpu(*lenp);
+
+ /* skip name offset, length */
+ offset += sizeof(struct fdt_property) - FDT_TAGSIZE;
+
+ if (!can_assume(VALID_DTB)
+ && !fdt_offset_ptr(fdt, offset, fdt32_to_cpu(*lenp)))
+ return FDT_END; /* premature end */
+
+ /* skip value */
+ offset += fdt32_to_cpu(*lenp);
+
if (!can_assume(LATEST) &&
fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 &&
((offset - fdt32_to_cpu(*lenp)) % 8) != 0)
@@ -197,7 +205,8 @@
return FDT_END;
}
- if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))
+ if (!can_assume(VALID_DTB) && (offset <= startoffset
+ || !fdt_offset_ptr(fdt, startoffset, offset - startoffset)))
return FDT_END; /* premature end */
*nextoffset = FDT_TAGALIGN(offset);