diff options
author | Milan Crha <mcrha@redhat.com> | 2021-09-02 17:42:39 +0200 |
---|---|---|
committer | Allen Winter <allen.winter@kdab.com> | 2021-09-19 09:15:44 -0400 |
commit | 57a4f675b2d31bb49d102beaaa778ee832f9e90e (patch) | |
tree | 6244b110716a39df1f4eb7f3b8615d3dc3773def /src/libicalvcal | |
parent | ecd309ba51c5aa7bc77e6b4220d0047d465337a4 (diff) | |
download | libical-git-57a4f675b2d31bb49d102beaaa778ee832f9e90e.tar.gz |
libicalvcal: Cast EOF to 'char' to ensure matching its value against it
Some arches (like aarch64, ppc64le and s390x) may not match the EOF
constant against its value cast to 'char'. That breaks the parser and
can cause an indefinite read of the content, with growing memory use.
Diffstat (limited to 'src/libicalvcal')
-rw-r--r-- | src/libicalvcal/vcc.c | 20 | ||||
-rw-r--r-- | src/libicalvcal/vcc.y | 20 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/libicalvcal/vcc.c b/src/libicalvcal/vcc.c index 00eb97ff..e5795867 100644 --- a/src/libicalvcal/vcc.c +++ b/src/libicalvcal/vcc.c @@ -744,7 +744,7 @@ static int lexGeta_(int i) } static void lexSkipLookahead() { - if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { + if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* don't skip EOF. */ lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; lexBuf.len--; @@ -779,7 +779,7 @@ static int lexLookahead() { static int lexGetc() { int c = lexLookahead(); - if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { + if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* EOF will remain in lookahead buffer */ lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; lexBuf.len--; @@ -829,7 +829,7 @@ static char* lexGetWord() { lexSkipWhite(); lexClearToken(); c = lexLookahead(); - while (c != EOF && !strchr("\t\n ;:=",c)) { + while (c != ((char) EOF) && !strchr("\t\n ;:=",c)) { lexAppendc(c); lexSkipLookahead(); c = lexLookahead(); @@ -841,7 +841,7 @@ static char* lexGetWord() { static void lexPushLookaheadc(int c) { int putptr; /* can't putback EOF, because it never leaves lookahead buffer */ - if (c == EOF) return; + if (((char) c) == ((char) EOF)) return; putptr = (int)lexBuf.getPtr - 1; if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; lexBuf.getPtr = (unsigned long)putptr; @@ -863,7 +863,7 @@ static char* lexLookaheadWord() { while (len < (MAX_LEX_LOOKAHEAD_0)) { c = lexGetc(); len++; - if (c == EOF || strchr("\t\n ;:=", c)) { + if (c == ((char) EOF) || strchr("\t\n ;:=", c)) { lexAppendc(0); /* restore lookahead buf. */ lexBuf.len += len; @@ -920,7 +920,7 @@ static char* lexGet1Value() { lexSkipWhite(); c = lexLookahead(); lexClearToken(); - while (c != EOF && c != ';') { + while (c != ((char) EOF) && c != ';') { if (c == '\n') { int a; lexSkipLookahead(); @@ -942,7 +942,7 @@ static char* lexGet1Value() { } lexAppendc(0); handleMoreRFC822LineBreak(c); - return c==EOF?0:lexStr(); + return c==((char) EOF)?0:lexStr(); } #endif @@ -1040,9 +1040,9 @@ static char * lexGetDataFromBase64() else if (oldBytes) free(oldBytes); /* error recovery: skip until 2 adjacent newlines. */ DBG_(("db: invalid character 0x%x '%c'\n", c,c)); - if (c != EOF) { + if (c != ((char) EOF)) { c = lexGetc(); - while (c != EOF) { + while (c != ((char) EOF)) { if (c == '\n' && lexLookahead() == '\n') { ++mime_lineNum; break; @@ -1260,7 +1260,7 @@ int yylex() { ++mime_lineNum; continue; } - case EOF: return 0; + case ((char) EOF): return 0; break; default: { lexPushLookaheadc(c); diff --git a/src/libicalvcal/vcc.y b/src/libicalvcal/vcc.y index 030ca442..73f87632 100644 --- a/src/libicalvcal/vcc.y +++ b/src/libicalvcal/vcc.y @@ -572,7 +572,7 @@ static int lexGeta_(int i) } static void lexSkipLookahead() { - if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { + if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* don't skip EOF. */ lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; lexBuf.len--; @@ -607,7 +607,7 @@ static int lexLookahead() { static int lexGetc() { int c = lexLookahead(); - if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { + if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* EOF will remain in lookahead buffer */ lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; lexBuf.len--; @@ -657,7 +657,7 @@ static char* lexGetWord() { lexSkipWhite(); lexClearToken(); c = lexLookahead(); - while (c != EOF && !strchr("\t\n ;:=",c)) { + while (c != ((char) EOF) && !strchr("\t\n ;:=",c)) { lexAppendc(c); lexSkipLookahead(); c = lexLookahead(); @@ -669,7 +669,7 @@ static char* lexGetWord() { static void lexPushLookaheadc(int c) { int putptr; /* can't putback EOF, because it never leaves lookahead buffer */ - if (c == EOF) return; + if (((char) c) == ((char) EOF)) return; putptr = (int)lexBuf.getPtr - 1; if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; lexBuf.getPtr = (unsigned long)putptr; @@ -691,7 +691,7 @@ static char* lexLookaheadWord() { while (len < (MAX_LEX_LOOKAHEAD_0)) { c = lexGetc(); len++; - if (c == EOF || strchr("\t\n ;:=", c)) { + if (c == ((char) EOF) || strchr("\t\n ;:=", c)) { lexAppendc(0); /* restore lookahead buf. */ lexBuf.len += len; @@ -748,7 +748,7 @@ static char* lexGet1Value() { lexSkipWhite(); c = lexLookahead(); lexClearToken(); - while (c != EOF && c != ';') { + while (c != ((char) EOF) && c != ';') { if (c == '\n') { int a; lexSkipLookahead(); @@ -770,7 +770,7 @@ static char* lexGet1Value() { } lexAppendc(0); handleMoreRFC822LineBreak(c); - return c==EOF?0:lexStr(); + return c==((char) EOF)?0:lexStr(); } #endif @@ -868,9 +868,9 @@ static char * lexGetDataFromBase64() else if (oldBytes) free(oldBytes); /* error recovery: skip until 2 adjacent newlines. */ DBG_(("db: invalid character 0x%x '%c'\n", c,c)); - if (c != EOF) { + if (c != ((char) EOF)) { c = lexGetc(); - while (c != EOF) { + while (c != ((char) EOF)) { if (c == '\n' && lexLookahead() == '\n') { ++mime_lineNum; break; @@ -1088,7 +1088,7 @@ int yylex() { ++mime_lineNum; continue; } - case EOF: return 0; + case ((char) EOF): return 0; break; default: { lexPushLookaheadc(c); |