dtc: Fix NULL pointer use in dtlabel + dtref case
PATCH 1/1 dtc: Fix NULL pointer use in dtlabel + dtref case
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 <[email protected]>
--- dtc-parser.y | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
dtc-parser.y +3 -3
@@ -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; }
Signature · 1 line
2.10.0.297.gf6727b0
A message that is not in the archive (sent off-list or not yet received): 20170125192724.11989-1-stephen.boyd-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Quoted 11 lines · Stephen Boyd
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 <[email protected]>
Looks good, but could you please add a testcase, so we don't make the same mistake in future.
Quoted 22 lines
--- dtc-parser.y | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)dtc-parser.y +3
-3@@ -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; }
Signature · 4 lines
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