Skip to content

Commit

Permalink
maplexer.l: fix heap-buffer-overflow issues with NUL characters
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 11, 2022
1 parent ea361a0 commit 10e0587
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 79 deletions.
89 changes: 44 additions & 45 deletions maplexer.c
Expand Up @@ -4518,8 +4518,8 @@ YY_RULE_SETUP
#line 504 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer,msyytext);
return(MS_STRING);
Expand All @@ -4530,8 +4530,8 @@ YY_RULE_SETUP
#line 512 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer,msyytext);
msyynumber = atof(msyytext);
Expand All @@ -4544,8 +4544,8 @@ YY_RULE_SETUP
#line 522 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer,msyytext);
return(MS_BINDING);
Expand Down Expand Up @@ -4582,8 +4582,8 @@ YY_RULE_SETUP
{
/* attribute binding - numeric (no quotes) */
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_TOKEN_BINDING_DOUBLE);
Expand All @@ -4596,8 +4596,8 @@ YY_RULE_SETUP
{
/* attribute binding - string (single or double quotes) */
msyytext+=2;
msyytext[strlen(msyytext)-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-2-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_TOKEN_BINDING_STRING);
Expand All @@ -4610,8 +4610,8 @@ YY_RULE_SETUP
{
/* attribute binding - time */
msyytext+=2;
msyytext[strlen(msyytext)-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-2-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_TOKEN_BINDING_TIME);
Expand All @@ -4621,7 +4621,7 @@ case 334:
YY_RULE_SETUP
#line 571 "maplexer.l"
{
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer,msyytext);
msyynumber = atof(msyytext);
Expand All @@ -4632,7 +4632,7 @@ case 335:
YY_RULE_SETUP
#line 579 "maplexer.l"
{
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer,msyytext);
msyynumber = atof(msyytext);
Expand All @@ -4645,8 +4645,8 @@ YY_RULE_SETUP
#line 587 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_TOKEN_LITERAL_TIME);
Expand All @@ -4658,8 +4658,8 @@ YY_RULE_SETUP
#line 596 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-2] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_IREGEX);
Expand All @@ -4671,8 +4671,8 @@ YY_RULE_SETUP
#line 605 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_REGEX);
Expand All @@ -4683,8 +4683,8 @@ YY_RULE_SETUP
#line 614 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_EXPRESSION);
Expand All @@ -4695,8 +4695,8 @@ YY_RULE_SETUP
#line 623 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
msyytext[msyyleng-1-1] = '\0';
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_LIST);
Expand All @@ -4720,7 +4720,7 @@ YY_RULE_SETUP
if (msyystring_begin == msyytext[0]) {
BEGIN(msyystring_begin_state);
if (msyystring_return_state == MS_STRING) {
if (msyystring_icase && strlen(msyytext)==2) {
if (msyystring_icase && msyyleng==2) {
msyystring_icase = MS_FALSE; // reset
return MS_ISTRING;
} else
Expand All @@ -4731,11 +4731,11 @@ YY_RULE_SETUP
}
else {
int old_size = msyystring_size;
msyystring_size += (strlen(msyytext)==2) ? 2 : 1;
msyystring_size += (msyyleng==2) ? 2 : 1;
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size,
msyystring_buffer_size);
msyystring_buffer[old_size] = *msyytext;
if (strlen(msyytext)==2) {
if (msyyleng==2) {
msyystring_buffer[old_size+1] = msyytext[1];
}
msyystring_buffer[msyystring_size] = '\0';
Expand All @@ -4750,7 +4750,7 @@ YY_RULE_SETUP
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size,
msyystring_buffer_size);

if (strlen(msyytext) == 2)
if (msyyleng == 2)
msyystring_buffer[msyystring_size-1] = msyytext[1];
else
msyystring_buffer[msyystring_size-1] = msyytext[0];
Expand All @@ -4763,20 +4763,19 @@ YY_RULE_SETUP
#line 678 "maplexer.l"
{
int old_size = msyystring_size;
int msyytext_len = (int)strlen(msyytext);
msyystring_size += msyytext_len;
msyystring_size += msyyleng;
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size,
msyystring_buffer_size);
memcpy(msyystring_buffer + old_size, msyytext, msyytext_len + 1);
memcpy(msyystring_buffer + old_size, msyytext, msyyleng + 1);
}
YY_BREAK
case 345:
/* rule 345 can match eol */
YY_RULE_SETUP
#line 687 "maplexer.l"
#line 686 "maplexer.l"
{
msyytext++;
msyytext[strlen(msyytext)-1] = '\0';
msyytext[msyyleng-1-1] = '\0';

if(include_stack_ptr >= MAX_INCLUDE_DEPTH) {
msSetError(MS_IOERR, "Includes nested to deeply.", "msyylex()");
Expand All @@ -4802,7 +4801,7 @@ YY_RULE_SETUP
YY_BREAK
case 346:
YY_RULE_SETUP
#line 713 "maplexer.l"
#line 712 "maplexer.l"
{
msyystring_return_state = MS_TOKEN_LITERAL_STRING;
msyystring_begin = msyytext[0];
Expand All @@ -4813,9 +4812,9 @@ YY_RULE_SETUP
YY_BREAK
case 347:
YY_RULE_SETUP
#line 721 "maplexer.l"
#line 720 "maplexer.l"
{
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(MS_STRING);
Expand All @@ -4824,11 +4823,11 @@ YY_RULE_SETUP
case 348:
/* rule 348 can match eol */
YY_RULE_SETUP
#line 728 "maplexer.l"
#line 727 "maplexer.l"
{ msyylineno++; }
YY_BREAK
case YY_STATE_EOF(INITIAL):
#line 730 "maplexer.l"
#line 729 "maplexer.l"
{
if( --include_stack_ptr < 0 )
return(EOF); /* end of main file */
Expand All @@ -4843,32 +4842,32 @@ case YY_STATE_EOF(INITIAL):
case 349:
/* rule 349 can match eol */
YY_RULE_SETUP
#line 741 "maplexer.l"
#line 740 "maplexer.l"
{
return(0);
}
YY_BREAK
case 350:
YY_RULE_SETUP
#line 745 "maplexer.l"
#line 744 "maplexer.l"
{
MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext),
MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng,
msyystring_buffer_size);
strcpy(msyystring_buffer, msyytext);
return(0);
}
YY_BREAK
case 351:
YY_RULE_SETUP
#line 751 "maplexer.l"
#line 750 "maplexer.l"
{ return(msyytext[0]); }
YY_BREAK
case 352:
YY_RULE_SETUP
#line 752 "maplexer.l"
#line 751 "maplexer.l"
ECHO;
YY_BREAK
#line 4872 "/home/even/mapserver/mapserver/maplexer.c"
#line 4871 "/home/even/mapserver/mapserver/maplexer.c"
case YY_STATE_EOF(URL_VARIABLE):
case YY_STATE_EOF(URL_STRING):
case YY_STATE_EOF(EXPRESSION_STRING):
Expand Down Expand Up @@ -5879,7 +5878,7 @@ void yyfree (void * ptr )

#define YYTABLES_NAME "yytables"

#line 752 "maplexer.l"
#line 751 "maplexer.l"


/*
Expand Down

0 comments on commit 10e0587

Please sign in to comment.