From: Daniel Stone Date: Wed, 15 Feb 2012 12:54:11 +0000 (+0000) Subject: xkbscan: Copy, rather than assign, file name X-Git-Tag: xkbcommon-0.2.0~794 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f01b144126617cb93248210a08749d5ba13dc94;p=platform%2Fupstream%2Flibxkbcommon.git 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 --- 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