preproc.: Fix NULL dereference on broken %strlen argument
authorCyrill Gorcunov <gorcunov@gmail.com>
Fri, 23 Jul 2010 14:51:51 +0000 (18:51 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Fri, 23 Jul 2010 14:51:51 +0000 (18:51 +0400)
Under particular circumstances %strlen may cause SIGSEG. A typical
example is %strlen with nonexistent macro argument.

[ Testcase test/strlen.asm ]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
preproc.c
test/strlen.asm [new file with mode: 0644]

index 7fc3e74d90df3af790ddf17736e50ae5a2f12b4e..d75b58eb339f75214c1f0f8dba16b9cbdf8fd4bf 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -3254,7 +3254,7 @@ issue_error:
         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,
                   "`%%strlen` requires string as second parameter");
             free_tlist(tline);
diff --git a/test/strlen.asm b/test/strlen.asm
new file mode 100644 (file)
index 0000000..913014c
--- /dev/null
@@ -0,0 +1,5 @@
+%macro strlen_test 1
+    %strlen len %2 ; not existing argument
+%endmacro
+
+strlen_test 'a'