8000 GCC 4.0 includes a new warning option, -Wformat-literal, that emits · tedx/postgres@a4c3f7d · GitHub
[go: up one dir, main page]

Skip to content

Commit a4c3f7d

Browse files
author
Neil Conway
committed
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. 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.
1 parent 6dce59c commit a4c3f7d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.42 2002/02/11 00:18:20 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.42.2.1 2005/04/30 09:08:14 neilc Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -391,7 +391,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
391391
* mode with libpq.
392392
*/
393393
if (te->copyStmt && strlen(te->copyStmt) > 0)
394-
ahprintf(AH, te->copyStmt);
394+
ahprintf(AH, "%s", te->copyStmt);
395395

396396
(*AH->PrintTocDataPtr) (AH, te, ropt);
397397

@@ -2006,7 +2006,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
20062006
appendPQExpBuffer(qry, " %s\n\n",
20072007
fmtId(user, false));
20082008

2009-
ahprintf(AH, qry->data);
2009+
ahprintf(AH, "%s", qry->data);
20102010

20112011
destroyPQExpBuffer(qry);
20122012
}

src/bin/pg_dump/pg_dump.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.241.2.3 2004/03/20 18:12:32 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.241.2.4 2005/04/30 09:08:14 neilc Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -436,7 +436,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
436436
{
437437
if (field > 0)
438438
appendPQExpBuffer(q, ",");
439-
appendPQExpBuffer(q, fmtId(PQfname(res, field), force_quotes));
439+
appendPQExpBufferStr(q, fmtId(PQfname(res, field), force_quotes));
440440
}
441441
appendPQExpBuffer(q, ") ");
442442
archprintf(fout, "%s", q->data);
@@ -2599,12 +2599,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs, const char *tablename)
25992599
if (tgisconstraint)
26002600
{
26012601
appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER ");
2602-
appendPQExpBuffer(query, fmtId(PQgetvalue(res2, i2, i_tgconstrname), force_quotes));
2602+
appendPQExpBufferStr(query, fmtId(PQgetvalue(res2, i2, i_tgconstrname), force_quotes));
26032603
}
26042604
else
26052605
{
26062606
appendPQExpBuffer(query, "CREATE TRIGGER ");
2607-
appendPQExpBuffer(query, fmtId(tgname, force_quotes));
2607+
appendPQExpBufferStr(query, fmtId(tgname, force_quotes));
26082608
}
26092609
appendPQExpBufferChar(query, ' ');
26102610
/* Trigger type */
@@ -4483,7 +4483,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
44834483
}
44844484

44854485
resetPQExpBuffer(id1);
4486-
appendPQExpBuffer(id1, fmtId(indinfo[i].indexrelname, force_quotes));
4486+
appendPQExpBufferStr(id1, fmtId(indinfo[i].indexrelname, force_quotes));
44874487

44884488
resetPQExpBuffer(q);
44894489
appendPQExpBuffer(q, "%s;\n", indinfo[i].indexdef);

0 commit comments

Comments
 (0)
0