diff options
author | Pierre-Clément Tosi <ptosi@google.com> | 2023-10-12 12:25:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-10-12 12:25:33 +0000 |
commit | 1fe80c59e93a3793b71dec7a138f8bfd061a4115 (patch) | |
tree | ec06b17c36f25f4ba710e03169de4536b23d8b4a | |
parent | 51f100644059874eb897bbf16cabda0e92d69877 (diff) | |
parent | b202d115bde8094148e386c34978910926f93f60 (diff) | |
download | dtc-1fe80c59e93a3793b71dec7a138f8bfd061a4115.tar.gz |
Merge changes I8efee39a,I5295898f into main
* changes:
FROMGIT: libfdt: fdt_path_offset_namelen: Reject empty path
ANDROID: Revert "libfdt: fdt_path_offset_namelen: Reject empty paths"
-rw-r--r-- | libfdt/fdt_ro.c | 2 | ||||
-rw-r--r-- | tests/path_offset.c | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 362cc4a..53db8ce 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -263,7 +263,7 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) FDT_RO_PROBE(fdt); - if (namelen < 1) + if (!can_assume(VALID_INPUT) && namelen <= 0) return -FDT_ERR_BADPATH; /* see if we have an alias */ diff --git a/tests/path_offset.c b/tests/path_offset.c index 82527d4..07e9d65 100644 --- a/tests/path_offset.c +++ b/tests/path_offset.c @@ -48,10 +48,13 @@ static void check_path_offset(void *fdt, char *path, int offset) verbose_printf("Checking offset of \"%s\" is %d...\n", path, offset); rc = fdt_path_offset(fdt, path); + if (rc == offset) + return; + if (rc < 0) FAIL("fdt_path_offset(\"%s\") failed: %s", path, fdt_strerror(rc)); - if (rc != offset) + else FAIL("fdt_path_offset(\"%s\") returned incorrect offset" " %d instead of %d", path, rc, offset); } @@ -102,6 +105,7 @@ int main(int argc, char *argv[]) check_path_offset(fdt, "/subnode@2/subsubnode", subsubnode2_offset2); /* Test paths with extraneous separators */ + check_path_offset(fdt, "", -FDT_ERR_BADPATH); check_path_offset(fdt, "//", 0); check_path_offset(fdt, "///", 0); check_path_offset(fdt, "//subnode@1", subnode1_offset); @@ -110,6 +114,8 @@ int main(int argc, char *argv[]) check_path_offset(fdt, "/subnode@2////subsubnode", subsubnode2_offset2); /* Test fdt_path_offset_namelen() */ + check_path_offset_namelen(fdt, "/subnode@1", -1, -FDT_ERR_BADPATH); + check_path_offset_namelen(fdt, "/subnode@1", 0, -FDT_ERR_BADPATH); check_path_offset_namelen(fdt, "/subnode@1", 1, 0); check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 10, subnode1_offset); check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 11, subnode1_offset); |