Commit 8f01b144126617cb93248210a08749d5ba13dc94

Daniel Stone 2012-02-15T12:54:11

xkbscan: Copy, rather than assign, file name 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>

diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 0c06715..33412bc 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -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)
diff --git a/src/xkbcomp/xkbscan.l b/src/xkbcomp/xkbscan.l
index bc0a849..0bb9681 100644
--- a/src/xkbcomp/xkbscan.l
+++ b/src/xkbcomp/xkbscan.l
@@ -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