From fba4a44c6f978793fe42ae32434aee1e92f0be7c Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Thu, 4 Aug 2022 09:56:58 +0000 Subject: [PATCH] [automerge] FROMGIT: libfdt: fdt_offset_ptr(): Fix comparison warnings 2p: 6f0fef2b2a 2p: 736c673f28 Original change: https://googleplex-android-review.googlesource.com/c/platform/external/dtc/+/19527650 Bug: 230794395 Change-Id: If2ae7bf5758338e71c69067b371e6a0bfe83048f Merged-In: Ice02ecc84d6e9ab30773d039a54664b259979521 (cherry picked from commit 7992e4aeb93afc9d36f7b18fdfa688227d1a9c20) Merged-In: If2ae7bf5758338e71c69067b371e6a0bfe83048f --- libfdt/fdt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libfdt/fdt.c b/libfdt/fdt.c index c28fcc1..82521b7 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -134,16 +134,20 @@ int fdt_check_header(const void *fdt) const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) { - unsigned absoffset = offset + fdt_off_dt_struct(fdt); + unsigned int uoffset = offset; + unsigned int absoffset = offset + fdt_off_dt_struct(fdt); + + if (offset < 0) + return NULL; if (!can_assume(VALID_INPUT)) - if ((absoffset < offset) + if ((absoffset < uoffset) || ((absoffset + len) < absoffset) || (absoffset + len) > fdt_totalsize(fdt)) return NULL; if (can_assume(LATEST) || fdt_version(fdt) >= 0x11) - if (((offset + len) < offset) + if (((uoffset + len) < uoffset) || ((offset + len) > fdt_size_dt_struct(fdt))) return NULL;