[Crosstoolchain-logs] [device-tree-compiler] 13/29: Fix widespread incorrect use of strneq(), replace with new strprefixeq()

Vagrant Cascadian vagrant at moszumanska.debian.org
Tue Jan 23 06:34:38 UTC 2018


This is an automated email from the git hooks/post-receive script.

vagrant pushed a commit to branch debian/master
in repository device-tree-compiler.

commit 7975f6422260af4ac7ae2fcdff0ef2a6e391ab71
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Sun Oct 29 22:54:09 2017 +0100

    Fix widespread incorrect use of strneq(), replace with new strprefixeq()
    
    Every remaining usage of strneq() is, in fact, incorrect.  They're trying
    to check that the first n characters of one string exactly match another
    string.  But, they fall into the classic trap of strncmp() on which
    strneq() is based.  If n is less than the length of the second string, they
    only check that the first string matches the start of the second, not the
    whole of it.
    
    To fix this, remove strneq() and replace it with a strprefixeq() function
    which does what we want here.
    
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 checks.c   | 6 +++---
 dtc.h      | 2 +-
 livetree.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/checks.c b/checks.c
index 770af32..f5bf5f9 100644
--- a/checks.c
+++ b/checks.c
@@ -696,8 +696,8 @@ static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *
 
 	node->bus = &pci_bus;
 
-	if (!strneq(node->name, "pci", node->basenamelen) &&
-	    !strneq(node->name, "pcie", node->basenamelen))
+	if (!strprefixeq(node->name, node->basenamelen, "pci") &&
+	    !strprefixeq(node->name, node->basenamelen, "pcie"))
 		FAIL(c, dti, "Node %s node name is not \"pci\" or \"pcie\"",
 			     node->fullpath);
 
@@ -828,7 +828,7 @@ static bool node_is_compatible(struct node *node, const char *compat)
 
 	for (str = prop->val.val, end = str + prop->val.len; str < end;
 	     str += strnlen(str, end - str) + 1) {
-		if (strneq(str, compat, end - str))
+		if (strprefixeq(str, end - str, compat))
 			return true;
 	}
 	return false;
diff --git a/dtc.h b/dtc.h
index bb0b91b..758eb7c 100644
--- a/dtc.h
+++ b/dtc.h
@@ -67,8 +67,8 @@ typedef uint32_t cell_t;
 
 
 #define streq(a, b)	(strcmp((a), (b)) == 0)
-#define strneq(a, b, n)	(strncmp((a), (b), (n)) == 0)
 #define strstarts(s, prefix)	(strncmp((s), (prefix), strlen(prefix)) == 0)
+#define strprefixeq(a, n, b)	(strlen(b) == (n) && (memcmp(a, b, n) == 0))
 
 #define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
 
diff --git a/livetree.c b/livetree.c
index 184703a..457d01e 100644
--- a/livetree.c
+++ b/livetree.c
@@ -507,7 +507,7 @@ struct node *get_node_by_path(struct node *tree, const char *path)
 
 	for_each_child(tree, child) {
 		if (p && (strlen(child->name) == p-path) &&
-				strneq(path, child->name, p-path))
+		    strprefixeq(path, p - path, child->name))
 			return get_node_by_path(child, p+1);
 		else if (!p && streq(path, child->name))
 			return child;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list