]> granicus.if.org Git - postgresql/commitdiff
Change addlit() to not assume its input is null-terminated, so that we
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Sep 2001 23:17:14 +0000 (23:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Sep 2001 23:17:14 +0000 (23:17 +0000)
don't have more bugs like the quote-quote-quote-quote one.  Propagate
fix into ecpg lexer, too.

src/backend/parser/scan.l
src/interfaces/ecpg/preproc/pgc.l

index 3f64341d5572c1b464fc9ce950e63d5ba54844b8..b071032972ab0a299559b72f0b89ccdf92f9baa4 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.89 2001/09/04 00:19:39 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.90 2001/09/07 23:17:14 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -69,6 +69,8 @@ void unput(char);
 
 extern YYSTYPE yylval;
 
+static int             xcdepth = 0;    /* depth of nesting in slash-star comments */
+
 /*
  * literalbuf is used to accumulate literal values when multiple rules
  * are needed to parse a single literal.  Call startlit to reset buffer
@@ -79,8 +81,6 @@ static char      *literalbuf;         /* expandable buffer */
 static int             literallen;             /* actual current length */
 static int             literalalloc;   /* current allocated buffer size */
 
-static int             xcdepth = 0;    /* depth of nesting in slash-star comments */
-
 #define startlit()  (literalbuf[0] = '\0', literallen = 0)
 static void addlit(char *ytext, int yleng);
 
@@ -375,7 +375,7 @@ other                       .
                                        return IDENT;
                                }
 <xd>{xddouble} {
-                                       addlit(yytext+1, yyleng-1);
+                                       addlit(yytext, yyleng-1);
                                }
 <xd>{xdinside} {
                                        addlit(yytext, yyleng);
@@ -581,9 +581,10 @@ addlit(char *ytext, int yleng)
                } while ((literallen+yleng) >= literalalloc);
                literalbuf = (char *) repalloc(literalbuf, literalalloc);
        }
-       /* append data --- note we assume ytext is null-terminated */
-       memcpy(literalbuf+literallen, ytext, yleng+1);
+       /* append new data, add trailing null */
+       memcpy(literalbuf+literallen, ytext, yleng);
        literallen += yleng;
+       literalbuf[literallen] = '\0';
 }
 
 #if !defined(FLEX_SCANNER)
index 5929f1f1713b6479de5ff3d24a0fce1f14207c0a..d6d99adcee391947113c04469f1f82fa2ad20085 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.79 2001/06/13 12:38:58 meskes Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.80 2001/09/07 23:17:14 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -35,6 +35,8 @@
 
 extern YYSTYPE yylval;
 
+static int             xcdepth = 0;    /* depth of nesting in slash-star comments */
+
 /*
  * literalbuf is used to accumulate literal values when multiple rules
  * are needed to parse a single literal.  Call startlit to reset buffer
@@ -45,8 +47,6 @@ static char      *literalbuf = NULL;          /* expandable buffer */
 static int             literallen;             /* actual current length */
 static int             literalalloc;   /* current allocated buffer size */
 
-static int             xcdepth = 0; 
-
 #define startlit()  (literalbuf[0] = '\0', literallen = 0)
 static void addlit(char *ytext, int yleng);
 
@@ -923,9 +923,10 @@ addlit(char *ytext, int yleng)
                } while ((literallen+yleng) >= literalalloc);
                literalbuf = (char *) realloc(literalbuf, literalalloc);
        }
-       /* append data --- note we assume ytext is null-terminated */
-       memcpy(literalbuf+literallen, ytext, yleng+1);
+       /* append new data, add trailing null */
+       memcpy(literalbuf+literallen, ytext, yleng);
        literallen += yleng;
+       literalbuf[literallen] = '\0';
 }
 
 int yywrap(void)