summaryrefslogtreecommitdiff
path: root/libfdt/fdt_ro.c
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2023-10-05 15:38:51 -0700
committer Xin Li <delphij@google.com> 2023-10-05 15:38:51 -0700
commitd7e38d805f6166b135015809518d5fa12d655265 (patch)
tree8b0a33cf8947283abdba0d74b104f2400fc6ac45 /libfdt/fdt_ro.c
parent11c0b06b54e0492b7fec14aede564f0034b7b975 (diff)
parent94ac09491592cdd6bb278dd14387abfaa883e7da (diff)
Merge Android 14
Bug: 298295554 Merged-In: I62ea59ee306eda58b764df2a9e5f2f33778e4b5c Change-Id: I610f13b78388d3d230aae815af74199632d12009
Diffstat (limited to 'libfdt/fdt_ro.c')
-rw-r--r--libfdt/fdt_ro.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 87d736b..a62ec78 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -10,6 +10,14 @@
#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)
{
@@ -531,13 +539,27 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
const char *fdt_get_alias_namelen(const void *fdt,
const char *name, int namelen)
{
+ const char *prop;
int aliasoffset;
+ int prop_len;
aliasoffset = fdt_path_offset(fdt, "/aliases");
if (aliasoffset < 0)
return NULL;
- return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
+ 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;
+ }
+ }
+
+ return prop;
}
const char *fdt_get_alias(const void *fdt, const char *name)