diff options
author | Neil Conway <neilc@samurai.com> | 2005-04-30 08:36:18 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2005-04-30 08:36:18 +0000 |
commit | a935e36ae9674f63887cdb7d94e1c31cb08e08c4 (patch) | |
tree | 3e3f32e9004f690770a261adbca69638f3a2abe1 | |
parent | 15ea6d5a2fdc57ef14ebf2c06f4f7392b6599899 (diff) | |
download | postgresql-a935e36ae9674f63887cdb7d94e1c31cb08e08c4.tar.gz postgresql-a935e36ae9674f63887cdb7d94e1c31cb08e08c4.zip |
GCC 4.0 includes a new warning option, -Wformat-literal, that emits
a warning when a variable is used as a format string for printf()
and similar functions (if the variable is derived from untrusted
data, it could include unexpected formatting sequences). This
emits too many warnings to be enabled by default, but it does
flag a few dubious constructs in the Postgres tree. This patch
fixes up the obvious variants: functions that are passed a variable
format string but no additional arguments.
Most of these are harmless (e.g. the ruleutils stuff), but there
is at least one actual bug here: if you create a trigger named
"%sfoo", pg_dump will read uninitialized memory and fail to dump
the trigger correctly.
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 26 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 6 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 8 |
3 files changed, 20 insertions, 20 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 42c5bd8ca5a..dab167c241d 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.157.2.3 2004/12/13 00:33:18 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.157.2.4 2005/04/30 08:36:17 neilc Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -741,7 +741,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags) AttrNumber attnum = idxrec->indkey[keyno]; if (!colno) - appendStringInfo(&buf, sep); + appendStringInfoString(&buf, sep); sep = ", "; if (attnum != 0) @@ -1814,7 +1814,7 @@ get_select_query_def(Query *query, deparse_context *context, Oid sortcoltype; TypeCacheEntry *typentry; - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sortexpr = get_rule_sortgroupclause(srt, query->targetList, force_colno, context); sortcoltype = exprType(sortexpr); @@ -1883,7 +1883,7 @@ get_basic_select_query(Query *query, deparse_context *context, { SortClause *srt = (SortClause *) lfirst(l); - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); get_rule_sortgroupclause(srt, query->targetList, false, context); sep = ", "; @@ -1905,7 +1905,7 @@ get_basic_select_query(Query *query, deparse_context *context, if (tle->resdom->resjunk) continue; /* ignore junk entries */ - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; colno++; @@ -1969,7 +1969,7 @@ get_basic_select_query(Query *query, deparse_context *context, { GroupClause *grp = (GroupClause *) lfirst(l); - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); get_rule_sortgroupclause(grp, query->targetList, false, context); sep = ", "; @@ -2153,7 +2153,7 @@ get_insert_query_def(Query *query, deparse_context *context) if (tle->resdom->resjunk) continue; /* ignore junk entries */ - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; appendStringInfo(buf, "%s", quote_identifier(get_relid_attribute_name(rte->relid, @@ -2174,7 +2174,7 @@ get_insert_query_def(Query *query, deparse_context *context) if (tle->resdom->resjunk) continue; /* ignore junk entries */ - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; get_rule_expr((Node *) tle->expr, context, false); } @@ -2221,7 +2221,7 @@ get_update_query_def(Query *query, deparse_context *context) if (tle->resdom->resjunk) continue; /* ignore junk entries */ - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; /* @@ -3085,7 +3085,7 @@ get_rule_expr(Node *node, deparse_context *context, { Node *e = (Node *) lfirst(element); - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); get_rule_expr(e, context, true); sep = ", "; } @@ -3105,7 +3105,7 @@ get_rule_expr(Node *node, deparse_context *context, { Node *e = (Node *) lfirst(arg); - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); get_rule_expr(e, context, true); sep = ", "; } @@ -3378,7 +3378,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context, sep = ""; foreach(l, expr->args) { - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; get_rule_expr((Node *) lfirst(l), context, true); } @@ -3612,7 +3612,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context) sep = ""; foreach(l, sublink->lefthand) { - appendStringInfo(buf, sep); + appendStringInfoString(buf, sep); sep = ", "; get_rule_expr((Node *) lfirst(l), context, true); } diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 41b573cea7e..e197624aef8 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79.2.3 2004/07/19 21:02:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79.2.4 2005/04/30 08:36:18 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -331,7 +331,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) * mode with libpq. */ if (te->copyStmt && strlen(te->copyStmt) > 0) - ahprintf(AH, te->copyStmt); + ahprintf(AH, "%s", te->copyStmt); (*AH->PrintTocDataPtr) (AH, te, ropt); @@ -2117,7 +2117,7 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user) appendPQExpBuffer(qry, " %s\n\n", fmtId(user)); - ahprintf(AH, qry->data); + ahprintf(AH, "%s", qry->data); destroyPQExpBuffer(qry); } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index ede8ad7c3a6..41370192d41 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.355.2.5 2004/05/26 18:27:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.355.2.6 2005/04/30 08:36:18 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -959,7 +959,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) { if (field > 0) appendPQExpBuffer(q, ", "); - appendPQExpBuffer(q, fmtId(PQfname(res, field))); + appendPQExpBufferStr(q, fmtId(PQfname(res, field))); } appendPQExpBuffer(q, ") "); archprintf(fout, "%s", q->data); @@ -6422,12 +6422,12 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) if (tgisconstraint) { appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER "); - appendPQExpBuffer(query, fmtId(PQgetvalue(res, j, i_tgconstrname))); + appendPQExpBufferStr(query, fmtId(PQgetvalue(res, j, i_tgconstrname))); } else { appendPQExpBuffer(query, "CREATE TRIGGER "); - appendPQExpBuffer(query, fmtId(tgname)); + appendPQExpBufferStr(query, fmtId(tgname)); } appendPQExpBuffer(query, "\n "); /* Trigger type */ |