Skip to content

Commit 09e99a1

Browse files
committed
Change addlit() to not assume its input is null-terminated, so that we
don't have more bugs like the quote-quote-quote-quote one. Propagate fix into ecpg lexer, too.
1 parent b6385ef commit 09e99a1

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/backend/parser/scan.l

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.89 2001/09/04 00:19:39 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.90 2001/09/07 23:17:14 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -69,6 +69,8 @@ void unput(char);
6969

7070
extern YYSTYPE yylval;
7171

72+
static int xcdepth = 0; /* depth of nesting in slash-star comments */
73+
7274
/*
7375
* literalbuf is used to accumulate literal values when multiple rules
7476
* are needed to parse a single literal. Call startlit to reset buffer
@@ -79,8 +81,6 @@ static char *literalbuf; /* expandable buffer */
7981
static int literallen; /* actual current length */
8082
static int literalalloc; /* current allocated buffer size */
8183

82-
static int xcdepth = 0; /* depth of nesting in slash-star comments */
83-
8484
#define startlit() (literalbuf[0] = '\0', literallen = 0)
8585
static void addlit(char *ytext, int yleng);
8686

@@ -375,7 +375,7 @@ other .
375375
return IDENT;
376376
}
377377
<xd>{xddouble} {
378-
addlit(yytext+1, yyleng-1);
378+
addlit(yytext, yyleng-1);
379379
}
380380
<xd>{xdinside} {
381381
addlit(yytext, yyleng);
@@ -581,9 +581,10 @@ addlit(char *ytext, int yleng)
581581
} while ((literallen+yleng) >= literalalloc);
582582
literalbuf = (char *) repalloc(literalbuf, literalalloc);
583583
}
584-
/* append data --- note we assume ytext is null-terminated */
585-
memcpy(literalbuf+literallen, ytext, yleng+1);
584+
/* append new data, add trailing null */
585+
memcpy(literalbuf+literallen, ytext, yleng);
586586
literallen += yleng;
587+
literalbuf[literallen] = '\0';
587588
}
588589

589590
#if !defined(FLEX_SCANNER)

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.79 2001/06/13 12:38:58 meskes Exp $
15+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.80 2001/09/07 23:17:14 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -35,6 +35,8 @@
3535

3636
extern YYSTYPE yylval;
3737

38+
static int xcdepth = 0; /* depth of nesting in slash-star comments */
39+
3840
/*
3941
* literalbuf is used to accumulate literal values when multiple rules
4042
* are needed to parse a single literal. Call startlit to reset buffer
@@ -45,8 +47,6 @@ static char *literalbuf = NULL; /* expandable buffer */
4547
static int literallen; /* actual current length */
4648
static int literalalloc; /* current allocated buffer size */
4749

48-
static int xcdepth = 0;
49-
5050
#define startlit() (literalbuf[0] = '\0', literallen = 0)
5151
static void addlit(char *ytext, int yleng);
5252

@@ -923,9 +923,10 @@ addlit(char *ytext, int yleng)
923923
} while ((literallen+yleng) >= literalalloc);
924924
literalbuf = (char *) realloc(literalbuf, literalalloc);
925925
}
926-
/* append data --- note we assume ytext is null-terminated */
927-
memcpy(literalbuf+literallen, ytext, yleng+1);
926+
/* append new data, add trailing null */
927+
memcpy(literalbuf+literallen, ytext, yleng);
928928
literallen += yleng;
929+
literalbuf[literallen] = '\0';
929930
}
930931

931932
int yywrap(void)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy