summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2008-02-27 13:45:13 +1100
committerJon Loeliger <jdl@loeliger.com>2008-03-23 08:00:32 -0500
commitfa5b520ccb5e8da8d67ebc1926416753684f4e70 (patch)
tree2fcb2d1c043c5c374279ea02bf63f9040daa254b
parent7c635dcb2f43529bbe7903f5a6ce56984d21b964 (diff)
downloaddtc-fa5b520ccb5e8da8d67ebc1926416753684f4e70.tar.gz
dtc: Implement checks for the format of node and property names
This patch adds checks to the checking framework to verify that node and property names contain only legal characters, and in the case of node names there is at most one '@'. At present when coming from dts input, this is mostly already ensured by the grammer, however putting the check later means its easier to generate helpful error messages rather than just "syntax error". For dtb input, these checks replace the older similar check built into flattree.c. Testcases for the checks are also implemented. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--checks.c37
-rw-r--r--flattree.c28
-rw-r--r--tests/dumptrees.c1
-rwxr-xr-xtests/run_tests.sh3
-rw-r--r--tests/testdata.h3
-rw-r--r--tests/trees.S48
6 files changed, 97 insertions, 23 deletions
diff --git a/checks.c b/checks.c
index 8c00c56..d92279e 100644
--- a/checks.c
+++ b/checks.c
@@ -242,6 +242,42 @@ static void check_duplicate_property_names(struct check *c, struct node *dt,
}
NODE_CHECK(duplicate_property_names, NULL, ERROR);
+#define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
+#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+#define DIGITS "0123456789"
+#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
+
+static void check_node_name_chars(struct check *c, struct node *dt,
+ struct node *node)
+{
+ int n = strspn(node->name, c->data);
+
+ if (n < strlen(node->name))
+ FAIL(c, "Bad character '%c' in node %s",
+ node->name[n], node->fullpath);
+}
+NODE_CHECK(node_name_chars, PROPNODECHARS "@", ERROR);
+
+static void check_node_name_format(struct check *c, struct node *dt,
+ struct node *node)
+{
+ if (strchr(get_unitname(node), '@'))
+ FAIL(c, "Node %s has multiple '@' characters in name",
+ node->fullpath);
+}
+NODE_CHECK(node_name_format, NULL, ERROR, &node_name_chars);
+
+static void check_property_name_chars(struct check *c, struct node *dt,
+ struct node *node, struct property *prop)
+{
+ int n = strspn(prop->name, c->data);
+
+ if (n < strlen(prop->name))
+ FAIL(c, "Bad character '%c' in property name \"%s\", node %s",
+ prop->name[n], prop->name, node->fullpath);
+}
+PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR);
+
static void check_explicit_phandles(struct check *c, struct node *root,
struct node *node)
{
@@ -498,6 +534,7 @@ TREE_CHECK(obsolete_chosen_interrupt_controller, NULL, WARN);
static struct check *check_table[] = {
&duplicate_node_names, &duplicate_property_names,
+ &node_name_chars, &node_name_format, &property_name_chars,
&name_is_string, &name_properties,
&explicit_phandles,
&phandle_references, &path_references,
diff --git a/flattree.c b/flattree.c
index 7b6d7fe..b6be786 100644
--- a/flattree.c
+++ b/flattree.c
@@ -729,29 +729,14 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
return strdup(lslash+1);
}
-static const char PROPCHAR[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,._+*#?-";
-static const char UNITCHAR[] = "0123456789abcdef,";
-
-static int check_node_name(const char *name)
+static int find_basenamelen(const char *name)
{
- const char *atpos;
- int basenamelen;
-
- atpos = strrchr(name, '@');
+ const char *atpos = strchr(name, '@');
if (atpos)
- basenamelen = atpos - name;
+ return atpos - name;
else
- basenamelen = strlen(name);
-
- if (strspn(name, PROPCHAR) < basenamelen)
- return -1;
-
- if (atpos
- && ((basenamelen + 1 + strspn(atpos+1, UNITCHAR)) < strlen(name)))
- return -1;
-
- return basenamelen;
+ return strlen(name);
}
static struct node *unflatten_tree(struct inbuf *dtbuf,
@@ -775,10 +760,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
node->fullpath = join_path(parent_path, node->name);
}
- node->basenamelen = check_node_name(node->name);
- if (node->basenamelen < 0) {
- fprintf(stderr, "Warning \"%s\" has incorrect format\n", node->name);
- }
+ node->basenamelen = find_basenamelen(node->name);
do {
struct property *prop;
diff --git a/tests/dumptrees.c b/tests/dumptrees.c
index ef48c0c..fa1f563 100644
--- a/tests/dumptrees.c
+++ b/tests/dumptrees.c
@@ -37,6 +37,7 @@ struct {
} trees[] = {
#define TREE(name) { &_##name, #name ".dtb" }
TREE(test_tree1),
+ TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
};
#define NUM_TREES (sizeof(trees) / sizeof(trees[0]))
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index c1da1fb..443177f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -188,6 +188,9 @@ dtc_tests () {
run_test dtc-checkfails.sh ranges_format -- -I dts -O dtb bad-empty-ranges.dts
run_test dtc-checkfails.sh avoid_default_addr_size -- -I dts -O dtb default-addr-size.dts
run_test dtc-checkfails.sh obsolete_chosen_interrupt_controller -- -I dts -O dtb obsolete-chosen-interrupt-controller.dts
+ run_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb
+ run_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb
+ run_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb
}
while getopts "vt:m" ARG ; do
diff --git a/tests/testdata.h b/tests/testdata.h
index 0f7f2fa..9c8b040 100644
--- a/tests/testdata.h
+++ b/tests/testdata.h
@@ -33,4 +33,7 @@
#ifndef __ASSEMBLY__
extern struct fdt_header _test_tree1;
extern struct fdt_header _truncated_property;
+extern struct fdt_header _bad_node_char;
+extern struct fdt_header _bad_node_format;
+extern struct fdt_header _bad_prop_char;
#endif /* ! __ASSEMBLY */
diff --git a/tests/trees.S b/tests/trees.S
index e3c5d47..cedf5f9 100644
--- a/tests/trees.S
+++ b/tests/trees.S
@@ -136,3 +136,51 @@ truncated_property_strings:
truncated_property_strings_end:
truncated_property_end:
+
+
+ TREE_HDR(bad_node_char)
+ EMPTY_RSVMAP(bad_node_char)
+
+bad_node_char_struct:
+ BEGIN_NODE("")
+ BEGIN_NODE("sub$node")
+ END_NODE
+ END_NODE
+ FDTLONG(FDT_END)
+bad_node_char_struct_end:
+
+bad_node_char_strings:
+bad_node_char_strings_end:
+bad_node_char_end:
+
+
+ TREE_HDR(bad_node_format)
+ EMPTY_RSVMAP(bad_node_format)
+
+bad_node_format_struct:
+ BEGIN_NODE("")
+ BEGIN_NODE("subnode@1@2")
+ END_NODE
+ END_NODE
+ FDTLONG(FDT_END)
+bad_node_format_struct_end:
+
+bad_node_format_strings:
+bad_node_format_strings_end:
+bad_node_format_end:
+
+
+ TREE_HDR(bad_prop_char)
+ EMPTY_RSVMAP(bad_prop_char)
+
+bad_prop_char_struct:
+ BEGIN_NODE("")
+ PROP_INT(bad_prop_char, prop, TEST_VALUE_1)
+ END_NODE
+ FDTLONG(FDT_END)
+bad_prop_char_struct_end:
+
+bad_prop_char_strings:
+ STRING(bad_prop_char, prop, "prop$erty")
+bad_prop_char_strings_end:
+bad_prop_char_end: