diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-02-27 23:18:52 +1100 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2023-03-01 17:55:35 +1100 |
commit | fd68bb8c56587114fa6eeed39c36c4b347a6a5fc (patch) | |
tree | 6f70106ddda74fab125f50471f489690e192180a /dtc-parser.y | |
parent | 4718189c4ca83ddaa38a4990bddd1d4196b11933 (diff) | |
download | dtc-fd68bb8c56587114fa6eeed39c36c4b347a6a5fc.zip dtc-fd68bb8c56587114fa6eeed39c36c4b347a6a5fc.tar.gz dtc-fd68bb8c56587114fa6eeed39c36c4b347a6a5fc.tar.bz2 |
Make name_node() xstrdup its name argument
The name field of 'struct node' was really always supposed to be a
malloc()ed string, that is owned by the structure. To avoid an extra
strdup() for strings coming up from the lexer, name_node() expects to take
uch an already malloc()ed string, which means it's not correct to pass it
a static string literal.
That's a pretty non-obvious constraint, so a bunch of incorrect uses have
crept in. Really, avoiding the extra dup from the lexer isn't a big enough
benefit for this demonstrably dangerous interface. So change it to do the
xstrdup() itself, removing the burden from callers.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-parser.y')
-rw-r--r-- | dtc-parser.y | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/dtc-parser.y b/dtc-parser.y index 9b724e5..4d5eece 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -573,10 +573,12 @@ subnode: DT_PROPNODENAME nodedef { $$ = name_node($2, $1); + free($1); } | DT_DEL_NODE DT_PROPNODENAME ';' { $$ = name_node(build_node_delete(&@$), $2); + free($2); } | DT_OMIT_NO_REF subnode { |