summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-11-01 21:43:59 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-11-01 21:43:59 +0000
commit3ac065d33a0a08ff9238f2dc639bb972eeecccc3 (patch)
treea56ffe61de902290b9f93461ea76d10ef68c5cd4
parent734529f4d2ae2c7542a375a3d628033321e9f8c2 (diff)
parent5ff63e185570909ff6dd1e45da78818261e656b6 (diff)
downloadlibufdt-android-platform-13.0.0_r5.tar.gz
Snap for 9239618 from 5ff63e185570909ff6dd1e45da78818261e656b6 to tm-platform-releaseandroid-platform-13.0.0_r5android-platform-13.0.0_r4android-platform-13.0.0_r3
Change-Id: I8b118bd2da1ca920451c6a0065005420f7d79f59
-rw-r--r--ufdt_convert.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/ufdt_convert.c b/ufdt_convert.c
index 5c69f1f..9e7922a 100644
--- a/ufdt_convert.c
+++ b/ufdt_convert.c
@@ -196,13 +196,21 @@ struct ufdt_node *ufdt_get_node_by_path_len(struct ufdt *tree, const char *path,
const char *alias_path =
ufdt_node_get_fdt_prop_data(aliases_node, &path_len);
- if (alias_path == NULL) {
- dto_error("Failed to find alias %s\n", path);
+ if (alias_path == NULL || path_len == 0) {
+ dto_error("Failed to find valid alias %s\n", path);
+ return NULL;
+ }
+
+ /* property data must be a nul terminated string */
+ int alias_len = strnlen(alias_path, path_len);
+
+ if (alias_len != path_len - 1 || alias_len == 0) {
+ dto_error("Invalid alias for %s\n", path);
return NULL;
}
struct ufdt_node *target_node =
- ufdt_node_get_node_by_path_len(tree->root, alias_path, path_len);
+ ufdt_node_get_node_by_path_len(tree->root, alias_path, alias_len);
return ufdt_node_get_node_by_path_len(target_node, next_slash,
end - next_slash);
@@ -292,9 +300,16 @@ struct ufdt *ufdt_from_fdt(void *fdtp, size_t fdt_size,
return ufdt_construct(NULL, pool);
}
- struct ufdt *res_tree = ufdt_construct(fdtp, pool);
int end_offset;
int start_tag = fdt_next_tag(fdtp, start_offset, &end_offset);
+
+ if (start_tag != FDT_BEGIN_NODE) {
+ return ufdt_construct(NULL, pool);
+ }
+
+ struct ufdt *res_tree = ufdt_construct(fdtp, pool);
+ if (res_tree == NULL) return NULL;
+
res_tree->root =
fdt_to_ufdt_tree(fdtp, start_offset, &end_offset, start_tag, pool);