devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Tim Montague <tmontague-5j0BnJlmnLM@public.gmane.org>
Cc: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH] Fix get_node_by_path string equality check
Date: Tue, 18 Apr 2017 12:05:40 +1000	[thread overview]
Message-ID: <20170418020540.GA12235@umbus.fritz.box> (raw)
In-Reply-To: <f5424c7ce8334730a64873b9912132d3-xbOadlNgr96L7B8feK0ILA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

On Tue, Apr 18, 2017 at 12:08:18AM +0000, Tim Montague wrote:
> When determining if to recurse into a node, get_node_by_path does not
> check if the length of each node name is equal.  If searching for
> /foo/baz, this can result in recursing into /food because
> strneq("foo", "food", 3) is true.
> 
> Signed-off-by: Tim Montague <tmontague-5j0BnJlmnLM@public.gmane.org>

Looks like I made the classic strncmp() blunder, how embarrassing.

Fix looks good, but I could trouble you to add a testcase exercising
this?


> ---
>  livetree.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/livetree.c b/livetree.c
> index 3673de0..aecd278 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -478,7 +478,8 @@ struct node *get_node_by_path(struct node *tree, const char *path)
>  	p = strchr(path, '/');
>  
>  	for_each_child(tree, child) {
> -		if (p && strneq(path, child->name, p-path))
> +		if (p && (strlen(child->name) == p-path) &&
> +				strneq(path, child->name, p-path))
>  			return get_node_by_path(child, p+1);
>  		else if (!p && streq(path, child->name))
>  			return child;

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2017-04-18  2:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-18  0:08 [PATCH] Fix get_node_by_path string equality check Tim Montague
     [not found] ` <f5424c7ce8334730a64873b9912132d3-xbOadlNgr96L7B8feK0ILA@public.gmane.org>
2017-04-18  2:05   ` David Gibson [this message]
     [not found]     ` <20170418020540.GA12235-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-04-18  3:18       ` Tim Montague
     [not found]         ` <77edbc7797e144cd9a635e5b1d0b2dfe-xbOadlNgr96L7B8feK0ILA@public.gmane.org>
2017-04-18  3:43           ` David Gibson
     [not found]             ` <20170418034332.GH12235-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-04-19  1:15               ` Tim Montague
     [not found]                 ` <7417379a9afc4272b5b62b8ff4e50719-xbOadlNgr96L7B8feK0ILA@public.gmane.org>
2017-04-19  1:30                   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170418020540.GA12235@umbus.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=tmontague-5j0BnJlmnLM@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).