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 <w...@the-dreams.de>
---
 src/input/vcd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/input/vcd.c b/src/input/vcd.c
index 765c9f7..0830d7d 100644
--- a/src/input/vcd.c
+++ b/src/input/vcd.c
@@ -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];
-- 
2.1.4


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to