mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
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.
This commit is contained in:
parent
15ea6d5a2f
commit
a935e36ae9
@ -3,7 +3,7 @@
|
|||||||
* back to source text
|
* back to source text
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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.
|
* 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];
|
AttrNumber attnum = idxrec->indkey[keyno];
|
||||||
|
|
||||||
if (!colno)
|
if (!colno)
|
||||||
appendStringInfo(&buf, sep);
|
appendStringInfoString(&buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
|
|
||||||
if (attnum != 0)
|
if (attnum != 0)
|
||||||
@ -1814,7 +1814,7 @@ get_select_query_def(Query *query, deparse_context *context,
|
|||||||
Oid sortcoltype;
|
Oid sortcoltype;
|
||||||
TypeCacheEntry *typentry;
|
TypeCacheEntry *typentry;
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sortexpr = get_rule_sortgroupclause(srt, query->targetList,
|
sortexpr = get_rule_sortgroupclause(srt, query->targetList,
|
||||||
force_colno, context);
|
force_colno, context);
|
||||||
sortcoltype = exprType(sortexpr);
|
sortcoltype = exprType(sortexpr);
|
||||||
@ -1883,7 +1883,7 @@ get_basic_select_query(Query *query, deparse_context *context,
|
|||||||
{
|
{
|
||||||
SortClause *srt = (SortClause *) lfirst(l);
|
SortClause *srt = (SortClause *) lfirst(l);
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
get_rule_sortgroupclause(srt, query->targetList,
|
get_rule_sortgroupclause(srt, query->targetList,
|
||||||
false, context);
|
false, context);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
@ -1905,7 +1905,7 @@ get_basic_select_query(Query *query, deparse_context *context,
|
|||||||
if (tle->resdom->resjunk)
|
if (tle->resdom->resjunk)
|
||||||
continue; /* ignore junk entries */
|
continue; /* ignore junk entries */
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
colno++;
|
colno++;
|
||||||
|
|
||||||
@ -1969,7 +1969,7 @@ get_basic_select_query(Query *query, deparse_context *context,
|
|||||||
{
|
{
|
||||||
GroupClause *grp = (GroupClause *) lfirst(l);
|
GroupClause *grp = (GroupClause *) lfirst(l);
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
get_rule_sortgroupclause(grp, query->targetList,
|
get_rule_sortgroupclause(grp, query->targetList,
|
||||||
false, context);
|
false, context);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
@ -2153,7 +2153,7 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
if (tle->resdom->resjunk)
|
if (tle->resdom->resjunk)
|
||||||
continue; /* ignore junk entries */
|
continue; /* ignore junk entries */
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
appendStringInfo(buf, "%s",
|
appendStringInfo(buf, "%s",
|
||||||
quote_identifier(get_relid_attribute_name(rte->relid,
|
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)
|
if (tle->resdom->resjunk)
|
||||||
continue; /* ignore junk entries */
|
continue; /* ignore junk entries */
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
get_rule_expr((Node *) tle->expr, context, false);
|
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)
|
if (tle->resdom->resjunk)
|
||||||
continue; /* ignore junk entries */
|
continue; /* ignore junk entries */
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3085,7 +3085,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
|||||||
{
|
{
|
||||||
Node *e = (Node *) lfirst(element);
|
Node *e = (Node *) lfirst(element);
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
get_rule_expr(e, context, true);
|
get_rule_expr(e, context, true);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
}
|
}
|
||||||
@ -3105,7 +3105,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
|||||||
{
|
{
|
||||||
Node *e = (Node *) lfirst(arg);
|
Node *e = (Node *) lfirst(arg);
|
||||||
|
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
get_rule_expr(e, context, true);
|
get_rule_expr(e, context, true);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
}
|
}
|
||||||
@ -3378,7 +3378,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
|
|||||||
sep = "";
|
sep = "";
|
||||||
foreach(l, expr->args)
|
foreach(l, expr->args)
|
||||||
{
|
{
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
get_rule_expr((Node *) lfirst(l), context, true);
|
get_rule_expr((Node *) lfirst(l), context, true);
|
||||||
}
|
}
|
||||||
@ -3612,7 +3612,7 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
|
|||||||
sep = "";
|
sep = "";
|
||||||
foreach(l, sublink->lefthand)
|
foreach(l, sublink->lefthand)
|
||||||
{
|
{
|
||||||
appendStringInfo(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
get_rule_expr((Node *) lfirst(l), context, true);
|
get_rule_expr((Node *) lfirst(l), context, true);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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.
|
* mode with libpq.
|
||||||
*/
|
*/
|
||||||
if (te->copyStmt && strlen(te->copyStmt) > 0)
|
if (te->copyStmt && strlen(te->copyStmt) > 0)
|
||||||
ahprintf(AH, te->copyStmt);
|
ahprintf(AH, "%s", te->copyStmt);
|
||||||
|
|
||||||
(*AH->PrintTocDataPtr) (AH, te, ropt);
|
(*AH->PrintTocDataPtr) (AH, te, ropt);
|
||||||
|
|
||||||
@ -2117,7 +2117,7 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
|
|||||||
appendPQExpBuffer(qry, " %s\n\n",
|
appendPQExpBuffer(qry, " %s\n\n",
|
||||||
fmtId(user));
|
fmtId(user));
|
||||||
|
|
||||||
ahprintf(AH, qry->data);
|
ahprintf(AH, "%s", qry->data);
|
||||||
|
|
||||||
destroyPQExpBuffer(qry);
|
destroyPQExpBuffer(qry);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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)
|
if (field > 0)
|
||||||
appendPQExpBuffer(q, ", ");
|
appendPQExpBuffer(q, ", ");
|
||||||
appendPQExpBuffer(q, fmtId(PQfname(res, field)));
|
appendPQExpBufferStr(q, fmtId(PQfname(res, field)));
|
||||||
}
|
}
|
||||||
appendPQExpBuffer(q, ") ");
|
appendPQExpBuffer(q, ") ");
|
||||||
archprintf(fout, "%s", q->data);
|
archprintf(fout, "%s", q->data);
|
||||||
@ -6422,12 +6422,12 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables)
|
|||||||
if (tgisconstraint)
|
if (tgisconstraint)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER ");
|
appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER ");
|
||||||
appendPQExpBuffer(query, fmtId(PQgetvalue(res, j, i_tgconstrname)));
|
appendPQExpBufferStr(query, fmtId(PQgetvalue(res, j, i_tgconstrname)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(query, "CREATE TRIGGER ");
|
appendPQExpBuffer(query, "CREATE TRIGGER ");
|
||||||
appendPQExpBuffer(query, fmtId(tgname));
|
appendPQExpBufferStr(query, fmtId(tgname));
|
||||||
}
|
}
|
||||||
appendPQExpBuffer(query, "\n ");
|
appendPQExpBuffer(query, "\n ");
|
||||||
/* Trigger type */
|
/* Trigger type */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user