From cdcd552041fc1325a2a81e3374fadb0dd15950dc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 11 Jul 2013 13:26:18 +1000 Subject: Always terminate the scanBuf string (#66345) If a key name exceeds 4 characters, the content of scanBuf is not null-terminated, giving error messages like syntax error: line 7 of test.xkb last scanned symbol is: FOOBARm Errors encountered in test.xkb; not compiled. (last character of the preceding 'maximum' statement in this case) X.Org Bug 66345 Signed-off-by: Peter Hutterer --- xkbscan.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'xkbscan.c') diff --git a/xkbscan.c b/xkbscan.c index 7b91b45..144f315 100644 --- a/xkbscan.c +++ b/xkbscan.c @@ -401,6 +401,7 @@ static int yyGetKeyName(void) { int ch, i; + int last; i = 0; while (((ch = scanchar()) != EOF) && (ch != '>')) @@ -466,12 +467,20 @@ yyGetKeyName(void) if (i < sizeof(scanBuf) - 1) scanBuf[i++] = ch; } + + if (i < sizeof(scanBuf) - i) + last = i; + else + last = sizeof(scanBuf) - 1; + + scanBuf[last] = '\0'; + if ((ch == '>') && (i < 5)) { - scanBuf[i++] = '\0'; scanStrLine = lineNum; return KEYNAME; } + return ERROR_TOK; } -- cgit v1.2.1