Fix NULL dereferences on %substr missing operands
authorCyrill Gorcunov <gorcunov@gmail.com>
Mon, 6 Sep 2010 19:49:52 +0000 (23:49 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Mon, 6 Sep 2010 20:10:23 +0000 (00:10 +0400)
%substr with dangling id issues SIGSEV. Fix it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
preproc.c

index e3b0c64038aab85c02a8f767e8d76cca844cba0f..22d30ca9cacea7a082ce95e903f5cb5aa9967a40 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -3395,12 +3395,13 @@ issue_error:
         tline = expand_smacro(tline->next);
         last->next = NULL;
 
-        t = tline->next;
+        if (tline) /* skip expanded id */
+            t = tline->next;
         while (tok_type_(t, TOK_WHITESPACE))
             t = t->next;
 
         /* t should now point to the string */
-        if (t->type != TOK_STRING) {
+        if (!tok_type_(t, TOK_STRING)) {
             error(ERR_NONFATAL,
                   "`%%substr` requires string as second parameter");
             free_tlist(tline);