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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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