GCC 4.0 includes a new warning option, -Wformat-literal, that emits
authorNeil Conway <[email protected]>
Sat, 30 Apr 2005 09:08:14 +0000 (09:08 +0000)
committerNeil Conway <[email protected]>
Sat, 30 Apr 2005 09:08:14 +0000 (09:08 +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.

This patch fixes a bug in pg_dump (triggers with formatting sequences
in their names are not dumped correctly) and some related pg_dump
code that looks dubious; cleanups for more harmless instances have
been applied to more recent branches. This patch also fixes an
additional format string bug that is present in 7.2 but not in later
releases: pg_dump would also fail to correctly dump indexes with
formatting sequences in their names.

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c

index 5b45fefc99fd2722356f50ac89b70fbc0e8eb8a6..427e25df963ce89d604ff67d89a742a5410331c9 100644 (file)
@@ -391,7 +391,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);
 
@@ -2006,7 +2006,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
                appendPQExpBuffer(qry, " %s\n\n",
                                                  fmtId(user, false));
 
-               ahprintf(AH, qry->data);
+               ahprintf(AH, "%s", qry->data);
 
                destroyPQExpBuffer(qry);
        }
index dc3563ee2a17d1a098907b9819b7a58988eebce3..1f252b5bab0d3454ae2e1a5f8f9f6ccb9008d5a3 100644 (file)
@@ -436,7 +436,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
                                {
                                        if (field > 0)
                                                appendPQExpBuffer(q, ",");
-                                       appendPQExpBuffer(q, fmtId(PQfname(res, field), force_quotes));
+                                       appendPQExpBufferStr(q, fmtId(PQfname(res, field), force_quotes));
                                }
                                appendPQExpBuffer(q, ") ");
                                archprintf(fout, "%s", q->data);
@@ -2599,12 +2599,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs, const char *tablename)
                                if (tgisconstraint)
                                {
                                        appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER ");
-                                       appendPQExpBuffer(query, fmtId(PQgetvalue(res2, i2, i_tgconstrname), force_quotes));
+                                       appendPQExpBufferStr(query, fmtId(PQgetvalue(res2, i2, i_tgconstrname), force_quotes));
                                }
                                else
                                {
                                        appendPQExpBuffer(query, "CREATE TRIGGER ");
-                                       appendPQExpBuffer(query, fmtId(tgname, force_quotes));
+                                       appendPQExpBufferStr(query, fmtId(tgname, force_quotes));
                                }
                                appendPQExpBufferChar(query, ' ');
                                /* Trigger type */
@@ -4483,7 +4483,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
                }
 
                resetPQExpBuffer(id1);
-               appendPQExpBuffer(id1, fmtId(indinfo[i].indexrelname, force_quotes));
+               appendPQExpBufferStr(id1, fmtId(indinfo[i].indexrelname, force_quotes));
 
                resetPQExpBuffer(q);
                appendPQExpBuffer(q, "%s;\n", indinfo[i].indexdef);