aboutsummaryrefslogtreecommitdiff
path: root/libfdt
diff options
context:
space:
mode:
authorFrank Mehnert <frank.mehnert@kernkonzept.com>2020-08-13 17:26:26 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2020-08-14 13:16:22 +1000
commit7bb86f1c09563f502c6ab0166feacf346e4e8c40 (patch)
tree7462544279d1b3addaf78555f39624c395737f9c /libfdt
parent3d522abc7571e1851ce71fcf0c3452ef287b1bab (diff)
downloaddtc-7bb86f1c09563f502c6ab0166feacf346e4e8c40.zip
dtc-7bb86f1c09563f502c6ab0166feacf346e4e8c40.tar.gz
dtc-7bb86f1c09563f502c6ab0166feacf346e4e8c40.tar.bz2
libfdt: fix fdt_check_node_offset_ w/ VALID_INPUT
fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set but only omit the initial offset check in that case. As this function works very similar to fdt_check_prop_offset_(), do the offset check there as well depending on ASSUME_VALID_INPUT. Message-Id: <1913141.TlUzK5foHS@noys4> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt')
-rw-r--r--libfdt/fdt.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index c28fcc1..37b7b93 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -206,10 +206,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
int fdt_check_node_offset_(const void *fdt, int offset)
{
- if (can_assume(VALID_INPUT))
- return offset;
- if ((offset < 0) || (offset % FDT_TAGSIZE)
- || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
+ if (!can_assume(VALID_INPUT)
+ && ((offset < 0) || (offset % FDT_TAGSIZE)))
+ return -FDT_ERR_BADOFFSET;
+
+ if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
return offset;
@@ -217,8 +218,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)
int fdt_check_prop_offset_(const void *fdt, int offset)
{
- if ((offset < 0) || (offset % FDT_TAGSIZE)
- || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))
+ if (!can_assume(VALID_INPUT)
+ && ((offset < 0) || (offset % FDT_TAGSIZE)))
+ return -FDT_ERR_BADOFFSET;
+
+ if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)
return -FDT_ERR_BADOFFSET;
return offset;