* [PATCH] dtc: Fix NULL pointer use in dtlabel + dtref case @ 2017-01-25 19:27 Stephen Boyd [not found] ` <20170125192724.11989-1-stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> 0 siblings, 1 reply; 2+ messages in thread From: Stephen Boyd @ 2017-01-25 19:27 UTC (permalink / raw) To: David Gibson; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA If we have a construct like this: label: &handle { ... }; Running dtc on it will cause a segfault, because we use 'target' when it could be NULL. Move the add_label() call into the if statement to fix this potentially bad use of a NULL pointer. Signed-off-by: Stephen Boyd <stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> --- dtc-parser.y | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index b2fd4d155839..ca3f5003427c 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -171,10 +171,10 @@ devicetree: { struct node *target = get_node_by_ref($1, $3); - add_label(&target->labels, $2); - if (target) + if (target) { + add_label(&target->labels, $2); merge_nodes(target, $4); - else + } else ERROR(&@3, "Label or path %s not found", $3); $$ = $1; } -- 2.10.0.297.gf6727b0 ^ permalink raw reply related [flat|nested] 2+ messages in thread
[parent not found: <20170125192724.11989-1-stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>]
* Re: [PATCH] dtc: Fix NULL pointer use in dtlabel + dtref case [not found] ` <20170125192724.11989-1-stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> @ 2017-01-30 4:48 ` David Gibson 0 siblings, 0 replies; 2+ messages in thread From: David Gibson @ 2017-01-30 4:48 UTC (permalink / raw) To: Stephen Boyd; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1309 bytes --] On Wed, Jan 25, 2017 at 11:27:24AM -0800, Stephen Boyd wrote: > If we have a construct like this: > > label: &handle { > ... > }; > > Running dtc on it will cause a segfault, because we use 'target' > when it could be NULL. Move the add_label() call into the if > statement to fix this potentially bad use of a NULL pointer. > > Signed-off-by: Stephen Boyd <stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> Looks good, but could you please add a testcase, so we don't make the same mistake in future. > --- > dtc-parser.y | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/dtc-parser.y b/dtc-parser.y > index b2fd4d155839..ca3f5003427c 100644 > --- a/dtc-parser.y > +++ b/dtc-parser.y > @@ -171,10 +171,10 @@ devicetree: > { > struct node *target = get_node_by_ref($1, $3); > > - add_label(&target->labels, $2); > - if (target) > + if (target) { > + add_label(&target->labels, $2); > merge_nodes(target, $4); > - else > + } else > ERROR(&@3, "Label or path %s not found", $3); > $$ = $1; > } -- 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 --] ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-30 4:48 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-01-25 19:27 [PATCH] dtc: Fix NULL pointer use in dtlabel + dtref case Stephen Boyd [not found] ` <20170125192724.11989-1-stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> 2017-01-30 4:48 ` David Gibson
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).