]> granicus.if.org Git - postgresql/commitdiff
GCC 4.0 includes a new warning option, -Wformat-literal, that emits
authorNeil Conway <neilc@samurai.com>
Sat, 30 Apr 2005 08:36:18 +0000 (08:36 +0000)
committerNeil Conway <neilc@samurai.com>
Sat, 30 Apr 2005 08:36:18 +0000 (08:36 +0000)
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.

src/backend/utils/adt/ruleutils.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c

index 42c5bd8ca5a9125f49418c5c7ed6f6e9856cf995..dab167c241de829eef70027253a8c57d00446533 100644 (file)
@@ -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);
                }
index 41b573cea7e1d010316cc8b8e1941be8fafeb1ec..e197624aef8992566dcf71e854f776bcda299804 100644 (file)
@@ -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);
        }
index ede8ad7c3a6c6eef3e61bee639557d29690168cd..41370192d4162b32848ad60fdb95952c9c121576 100644 (file)
@@ -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 */