diff options
author | Pierre-Clément Tosi <ptosi@google.com> | 2023-10-12 15:15:50 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-10-12 15:15:50 +0000 |
commit | 802f98b18936b17a9b58e94bcfda678b5c933c9d (patch) | |
tree | 6592a432c0666810878e34f66af02ae02fe0a068 | |
parent | c2970dd8f8aa627226d3c3b8c16a415ecf206655 (diff) | |
parent | 5ec1ec09d03945cfde95c5c018c23b2e94552089 (diff) | |
download | dtc-802f98b18936b17a9b58e94bcfda678b5c933c9d.tar.gz |
Merge changes I1e5a8903,I43c6ad22,If9a102a6,I702e619c into main am: e5b8c171c5 am: 132ab4d211 am: 59703fa923 am: cc558f2f2a am: 5ec1ec09d0
Original change: https://android-review.googlesource.com/c/platform/external/dtc/+/2784253
Change-Id: I7aad50747418f387e4f6e8c01404a2caf6b2316c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | libfdt/fdt_ro.c | 45 | ||||
-rw-r--r-- | tests/aliases.dts | 4 | ||||
-rw-r--r-- | tests/get_alias.c | 14 |
3 files changed, 36 insertions, 27 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 53db8ce..09d92d4 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -10,14 +10,6 @@ #include "libfdt_internal.h" -/* Check if a buffer contains a nul-terminated string. - * Used for checking property values which should be strings. - */ -static bool is_nul_string(const char *buf, const size_t buf_len) { - return buf_len > 0 && buf[buf_len - 1] == '\0' && - strnlen(buf, buf_len) == buf_len - 1; -} - static int fdt_nodename_eq_(const void *fdt, int offset, const char *s, int len) { @@ -533,30 +525,31 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) return fdt32_ld_(php); } +static const void *fdt_path_getprop_namelen(const void *fdt, const char *path, + const char *propname, int propnamelen, + int *lenp) +{ + int offset = fdt_path_offset(fdt, path); + + if (offset < 0) + return NULL; + + return fdt_getprop_namelen(fdt, offset, propname, propnamelen, lenp); +} + const char *fdt_get_alias_namelen(const void *fdt, const char *name, int namelen) { - const char *prop; - int aliasoffset; - int prop_len; + int len; + const char *alias; - aliasoffset = fdt_path_offset(fdt, "/aliases"); - if (aliasoffset < 0) - return NULL; + alias = fdt_path_getprop_namelen(fdt, "/aliases", name, namelen, &len); - prop = fdt_getprop_namelen(fdt, aliasoffset, name, namelen, &prop_len); - if (prop && !can_assume(VALID_INPUT)) { - /* Validate the alias value. From the devicetree spec v0.3: - * "An alias value is a device path and is encoded as a string. - * The value representes the full path to a node, ..." - * A full path must start at the root to prevent recursion. - */ - if (prop_len == 0 || *prop != '/' || !is_nul_string(prop, prop_len)) { - prop = NULL; - } - } + if (!can_assume(VALID_DTB) && + !(alias && len > 0 && alias[len - 1] == '\0' && *alias == '/')) + return NULL; - return prop; + return alias; } const char *fdt_get_alias(const void *fdt, const char *name) diff --git a/tests/aliases.dts b/tests/aliases.dts index 853479a..03ed675 100644 --- a/tests/aliases.dts +++ b/tests/aliases.dts @@ -5,6 +5,10 @@ #size-cells = <0>; aliases { + empty = ""; + loop = "loop"; + nonull = [626164]; + relative = "s1/subsubnode"; s1 = &sub1; ss1 = &subsub1; sss1 = &subsubsub1; diff --git a/tests/get_alias.c b/tests/get_alias.c index fb2c38c..d2888d6 100644 --- a/tests/get_alias.c +++ b/tests/get_alias.c @@ -21,9 +21,16 @@ static void check_alias(void *fdt, const char *path, const char *alias) aliaspath = fdt_get_alias(fdt, alias); - if (path && !aliaspath) + if (!path && !aliaspath) + return; + + if (!aliaspath) FAIL("fdt_get_alias(%s) failed\n", alias); + if (!path) + FAIL("fdt_get_alias(%s) returned %s instead of NULL", + alias, aliaspath); + if (strcmp(aliaspath, path) != 0) FAIL("fdt_get_alias(%s) returned %s instead of %s\n", alias, aliaspath, path); @@ -36,9 +43,14 @@ int main(int argc, char *argv[]) test_init(argc, argv); fdt = load_blob_arg(argc, argv); + check_alias(fdt, NULL, "empty"); + check_alias(fdt, NULL, "nonull"); + check_alias(fdt, NULL, "relative"); check_alias(fdt, "/subnode@1", "s1"); check_alias(fdt, "/subnode@1/subsubnode", "ss1"); check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1"); + check_alias(fdt, NULL, "loop"); // Might trigger a stack overflow + PASS(); } |