]> sigrok.org Git - libsigrok.git/commitdiff
input: vcd: properly bail out on missing identifiers
authorWolfram Sang <redacted>
Sat, 9 Jan 2016 16:40:10 +0000 (17:40 +0100)
committerUwe Hermann <redacted>
Thu, 28 Jan 2016 18:03:53 +0000 (19:03 +0100)
If we hit the missing identifier case, then we reached the end of the
token list. So, we should break out of the loop, and not continue.
Otherwise we will go past the end of the array as this minimal testcase
shows:

$timescale 1 ns $end
$var wire 1 n0 addr_0 $end
$enddefinitions $end
1

gives:

$ ./sigrok-cli -I vcd -i no_mod.vcd -O vcd -o /tmp/o.vcd
Segmentation fault

Signed-off-by: Wolfram Sang <redacted>
src/input/vcd.c

index e4a4e7278062169f27a01149fc811c1e6d1542cc..91c22fcaea30df775d6726f25cdc45e29afa582c 100644 (file)
@@ -418,9 +418,10 @@ static void parse_contents(const struct sr_input *in, char *data)
                         * there was whitespace after the bit, the next token.
                         */
                        if (tokens[i][1] == '\0') {
-                               if (!tokens[++i])
-                                       /* Missing identifier */
-                                       continue;
+                               if (!tokens[++i]) {
+                                       sr_dbg("Identifier missing!");
+                                       break;
+                               }
                        } else {
                                for (j = 1; tokens[i][j]; j++)
                                        tokens[i][j - 1] = tokens[i][j];