diff options
| author | Bruce Momjian <bruce@momjian.us> | 2002-09-02 06:11:43 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2002-09-02 06:11:43 +0000 |
| commit | a12b4e279bc12a7cd7b7d679fcac4689ac4aba7b (patch) | |
| tree | ff120ff0c156829d771bdc874fe8fbb2aa4fbf6e /src/interfaces | |
| parent | 48e1a39924d9e0674306156a6519cf5688c67c43 (diff) | |
I checked all the previous string handling errors and most of them were
already fixed by You. However there were a few left and attached patch
should fix the rest of them.
I used StringInfo only in 2 places and both of them are inside debug
ifdefs. Only performance penalty will come from using strlen() like all
the other code does.
I also modified some of the already patched parts by changing
snprintf(buf, 2 * BUFSIZE, ... style lines to
snprintf(buf, sizeof(buf), ... where buf is an array.
Jukka Holappa
Diffstat (limited to 'src/interfaces')
| -rw-r--r-- | src/interfaces/ecpg/preproc/pgc.l | 8 | ||||
| -rw-r--r-- | src/interfaces/ecpg/preproc/preproc.y | 30 | ||||
| -rw-r--r-- | src/interfaces/ecpg/preproc/variable.c | 12 | ||||
| -rw-r--r-- | src/interfaces/libpgtcl/pgtclCmds.c | 5 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-auth.c | 8 |
5 files changed, 32 insertions, 31 deletions
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 20f08b6182a..d9d09d90f75 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.98 2002/07/30 16:33:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.99 2002/09/02 06:11:42 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -405,7 +405,7 @@ cppline {space}*#(.*\\{space})*.* mmerror(PARSE_ERROR, ET_ERROR, "zero-length delimited identifier"); if (literallen >= NAMEDATALEN) { - sprintf(errortext, "identifier \"%s\" will be truncated to \"%.*s\"", + snprintf(errortext, sizeof(errortext), "identifier \"%s\" will be truncated to \"%.*s\"", literalbuf, NAMEDATALEN-1, literalbuf); literalbuf[NAMEDATALEN-1] = '\0'; mmerror(PARSE_ERROR, ET_WARNING, errortext); @@ -831,7 +831,7 @@ cppline {space}*#(.*\\{space})*.* fprintf(stderr, "Error: Path %s/%s is too long in line %d, skipping.\n", ip->path, yytext, yylineno); continue; } - sprintf (inc_file, "%s/%s", ip->path, yytext); + snprintf (inc_file, sizeof(inc_file), "%s/%s", ip->path, yytext); yyin = fopen( inc_file, "r" ); if (!yyin) { @@ -844,7 +844,7 @@ cppline {space}*#(.*\\{space})*.* } if (!yyin) { - sprintf(errortext, "Cannot open include file %s in line %d\n", yytext, yylineno); + snprintf(errortext, sizeof(errortext), "Cannot open include file %s in line %d\n", yytext, yylineno); mmerror(NO_INCLUDE_FILE, ET_FATAL, errortext); } diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 008523350e1..7069d5611d7 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.195 2002/07/21 11:09:41 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.196 2002/09/02 06:11:43 momjian Exp $ */ /* Copyright comment */ %{ @@ -582,7 +582,7 @@ stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); } if (ptr == NULL) { - sprintf(errortext, "trying to open undeclared cursor %s\n", $1); + snprintf(errortext, sizeof(errortext), "trying to open undeclared cursor %s\n", $1); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -1119,7 +1119,7 @@ columnDef: ColId Typename ColQualList opt_collate { if (strlen($4) > 0) { - sprintf(errortext, "Currently unsupported CREATE TABLE / COLLATE %s will be passed to backend", $4); + snprintf(errortext, sizeof(errortext), "Currently unsupported CREATE TABLE / COLLATE %s will be passed to backend", $4); mmerror(PARSE_ERROR, ET_WARNING, errortext); } $$ = cat_str(4, $1, $2, $3, $4); @@ -2406,7 +2406,7 @@ CursorStmt: DECLARE name opt_cursor CURSOR FOR SelectStmt if (strcmp($2, ptr->name) == 0) { /* re-definition is a bug */ - sprintf(errortext, "cursor %s already defined", $2); + snprintf(errortext, sizeof(errortext), "cursor %s already defined", $2); mmerror(PARSE_ERROR, ET_ERROR, errortext); } } @@ -3628,7 +3628,7 @@ connection_target: database_name opt_server opt_port /* old style: dbname[@server][:port] */ if (strlen($2) > 0 && *($2) != '@') { - sprintf(errortext, "Expected '@', found '%s'", $2); + sprintf(errortext, sizeof(errortext), "Expected '@', found '%s'", $2); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3639,13 +3639,13 @@ connection_target: database_name opt_server opt_port /* new style: <tcp|unix>:postgresql://server[:port][/dbname] */ if (strncmp($1, "unix:postgresql", strlen("unix:postgresql")) != 0 && strncmp($1, "tcp:postgresql", strlen("tcp:postgresql")) != 0) { - sprintf(errortext, "only protocols 'tcp' and 'unix' and database type 'postgresql' are supported"); + snprintf(errortext, sizeof(errortext), "only protocols 'tcp' and 'unix' and database type 'postgresql' are supported"); mmerror(PARSE_ERROR, ET_ERROR, errortext); } if (strncmp($3, "//", strlen("//")) != 0) { - sprintf(errortext, "Expected '://', found '%s'", $3); + snprintf(errortext, sizeof(errortext), "Expected '://', found '%s'", $3); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3653,7 +3653,7 @@ connection_target: database_name opt_server opt_port strncmp($3 + strlen("//"), "localhost", strlen("localhost")) != 0 && strncmp($3 + strlen("//"), "127.0.0.1", strlen("127.0.0.1")) != 0) { - sprintf(errortext, "unix domain sockets only work on 'localhost' but not on '%9.9s'", $3 + strlen("//")); + snprintf(errortext, sizeof(errortext), "unix domain sockets only work on 'localhost' but not on '%9.9s'", $3 + strlen("//")); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3686,13 +3686,13 @@ db_prefix: ident CVARIABLE { if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0) { - sprintf(errortext, "Expected 'postgresql', found '%s'", $2); + snprintf(errortext, sizeof(errortext), "Expected 'postgresql', found '%s'", $2); mmerror(PARSE_ERROR, ET_ERROR, errortext); } if (strcmp($1, "tcp") != 0 && strcmp($1, "unix") != 0) { - sprintf(errortext, "Illegal connection type %s", $1); + snprintf(errortext, sizeof(errortext), "Illegal connection type %s", $1); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3704,7 +3704,7 @@ server: Op server_name { if (strcmp($1, "@") != 0 && strcmp($1, "//") != 0) { - sprintf(errortext, "Expected '@' or '://', found '%s'", $1); + snprintf(errortext, sizeof(errortext), "Expected '@' or '://', found '%s'", $1); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3806,7 +3806,7 @@ opt_options: Op ColId if (strcmp($1, "?") != 0) { - sprintf(errortext, "unrecognised token '%s'", $1); + snprintf(errortext, sizeof(errortext), "unrecognised token '%s'", $1); mmerror(PARSE_ERROR, ET_ERROR, errortext); } @@ -3829,7 +3829,7 @@ ECPGCursorStmt: DECLARE name opt_cursor CURSOR FOR ident if (strcmp($2, ptr->name) == 0) { /* re-definition is a bug */ - sprintf(errortext, "cursor %s already defined", $2); + snprintf(errortext, sizeof(errortext), "cursor %s already defined", $2); mmerror(PARSE_ERROR, ET_ERROR, errortext); } } @@ -3923,7 +3923,7 @@ type_declaration: S_TYPEDEF if (strcmp($5, ptr->name) == 0) { /* re-definition is a bug */ - sprintf(errortext, "Type %s already defined", $5); + snprintf(errortext, sizeof(errortext), "Type %s already defined", $5); mmerror(PARSE_ERROR, ET_ERROR, errortext); } } @@ -4528,7 +4528,7 @@ ECPGTypedef: TYPE_P if (strcmp($3, ptr->name) == 0) { /* re-definition is a bug */ - sprintf(errortext, "Type %s already defined", $3); + snprintf(errortext, sizeof(errortext), "Type %s already defined", $3); mmerror(PARSE_ERROR, ET_ERROR, errortext); } } diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index cee7ab3cf50..fd8b7c97943 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -80,13 +80,13 @@ find_struct(char *name, char *next) { if (p->type->type != ECPGt_array) { - sprintf(errortext, "variable %s is not a pointer", name); + snprintf(errortext, sizeof(errortext), "variable %s is not a pointer", name); mmerror(PARSE_ERROR, ET_FATAL, errortext); } if (p->type->u.element->type != ECPGt_struct && p->type->u.element->type != ECPGt_union) { - sprintf(errortext, "variable %s is not a pointer to a structure or a union", name); + snprintf(errortext, sizeof(errortext), "variable %s is not a pointer to a structure or a union", name); mmerror(PARSE_ERROR, ET_FATAL, errortext); } @@ -100,7 +100,7 @@ find_struct(char *name, char *next) { if (p->type->type != ECPGt_struct && p->type->type != ECPGt_union) { - sprintf(errortext, "variable %s is neither a structure nor a union", name); + snprintf(errortext, sizeof(errortext), "variable %s is neither a structure nor a union", name); mmerror(PARSE_ERROR, ET_FATAL, errortext); } @@ -142,7 +142,7 @@ find_variable(char *name) if (p == NULL) { - sprintf(errortext, "The variable %s is not declared", name); + snprintf(errortext, sizeof(errortext), "The variable %s is not declared", name); mmerror(PARSE_ERROR, ET_FATAL, errortext); } @@ -290,7 +290,7 @@ get_typedef(char *name) for (this = types; this && strcmp(this->name, name); this = this->next); if (!this) { - sprintf(errortext, "invalid datatype '%s'", name); + snprintf(errortext, sizeof(errortext), "invalid datatype '%s'", name); mmerror(PARSE_ERROR, ET_FATAL, errortext); } @@ -320,7 +320,7 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim } if (pointer_len>2) - { sprintf(errortext, "No multilevel (more than 2) pointer supported %d",pointer_len); + { snprintf(errortext, sizeof(errortext), "No multilevel (more than 2) pointer supported %d",pointer_len); mmerror(PARSE_ERROR, ET_FATAL, errortext); /* mmerror(PARSE_ERROR, ET_FATAL, "No multilevel (more than 2) pointer supported %d",pointer_len);*/ } diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c index 0cb46686dc1..901bcbfd329 100644 --- a/src/interfaces/libpgtcl/pgtclCmds.c +++ b/src/interfaces/libpgtcl/pgtclCmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.64 2002/08/18 01:39:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.65 2002/09/02 06:11:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1579,7 +1579,8 @@ Pg_lo_import(ClientData cData, Tcl_Interp *interp, int argc, char *argv[]) lobjId = lo_import(conn, filename); if (lobjId == InvalidOid) { - sprintf(interp->result, "Pg_lo_import of '%s' failed", filename); + /* What is the maximum size of this? FIXME if this is not a good quess */ + snprintf(interp->result, 128, "Pg_lo_import of '%s' failed", filename); return TCL_ERROR; } sprintf(interp->result, "%u", lobjId); diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 317cf772a75..dbca53c5850 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -10,7 +10,7 @@ * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.69 2002/08/29 03:22:01 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.70 2002/09/02 06:11:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -142,7 +142,7 @@ pg_krb4_init() { char tktbuf[MAXPGPATH]; - (void) sprintf(tktbuf, "%s@%s", tkt_string(), realm); + (void) snprintf(tktbuf, sizeof(tktbuf), "%s@%s", tkt_string(), realm); krb_set_tkt_string(tktbuf); } } @@ -618,13 +618,13 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, case AUTH_REQ_PASSWORD: if (password == NULL || *password == '\0') { - (void) sprintf(PQerrormsg, + (void) snprintf(PQerrormsg, PQERRORMSG_LENGTH, "fe_sendauth: no password supplied\n"); return STATUS_ERROR; } if (pg_password_sendauth(conn, password, areq) != STATUS_OK) { - (void) sprintf(PQerrormsg, + (void) snprintf(PQerrormsg, PQERRORMSG_LENGTH, "fe_sendauth: error sending password authentication\n"); return STATUS_ERROR; } |
