xkbscan: Copy, rather than assign, file name
authorDaniel Stone <daniel@fooishbar.org>
Wed, 15 Feb 2012 12:54:11 +0000 (12:54 +0000)
committerDaniel Stone <daniel@fooishbar.org>
Wed, 15 Feb 2012 16:24:50 +0000 (16:24 +0000)
For some reason, lex decided to reduce a strcpy into an assignment,
leading to entirely justified valgrind warnings about invalid reads,
when scanFile was set to a string which may have only ever lived on the
stack of a now-exited function.

Make it a strdup() instead.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
src/xkbcomp/misc.c
src/xkbcomp/xkbscan.l

index 0c06715..33412bc 100644 (file)
@@ -70,7 +70,10 @@ ProcessIncludeFile(IncludeStmt * stmt,
                    XkbDirectoryForInclude(file_type));
             return False;
         }
-        strcpy(oldFile, scanFile);
+        if (scanFile)
+            strcpy(oldFile, scanFile);
+        else
+            memset(oldFile, 0, sizeof(oldFile));
         oldLine = lineNum;
         setScanState(stmt->file, 1);
         if (debugFlags & 2)
index bc0a849..0bb9681 100644 (file)
@@ -35,8 +35,7 @@
 #include "parseutils.h"
 
 const char *yystring;
-static char scanFileBuf[1024] = {0};
-char *scanFile = scanFileBuf;
+char *scanFile = NULL;
 int lineNum = 0;
 
 int scanInt;
@@ -196,8 +195,9 @@ yyerror(const char *s)
 void setScanState(char *file, int lineno)
 {
   yylineno = 1;
-  strncpy(scanFile, file, 1023);
-  scanFile[1023]='\0';
+  if (scanFile)
+    free(scanFile);
+  scanFile = strdup(file);
 }
 
 int