Skip to content

Commit 1e2f941

Browse files
committed
Avoid use of sprintf/snprintf in describe.c.
Most places were already using the PQExpBuffer library for constructing variable-length strings; bring the two stragglers into line. describeOneTSParser was living particularly dangerously since it wasn't even using snprintf(). Daniel Gustafsson Discussion: https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
1 parent b884f62 commit 1e2f941

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/bin/psql/describe.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,7 +4113,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
41134113
{
41144114
PQExpBufferData buf;
41154115
PGresult *res;
4116-
char title[1024];
4116+
PQExpBufferData title;
41174117
printQueryOpt myopt = pset.popt;
41184118
static const bool translate_columns[] = {true, false, false};
41194119

@@ -4169,11 +4169,13 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
41694169
return false;
41704170

41714171
myopt.nullPrint = NULL;
4172+
initPQExpBuffer(&title);
41724173
if (nspname)
4173-
sprintf(title, _("Text search parser \"%s.%s\""), nspname, prsname);
4174+
printfPQExpBuffer(&title, _("Text search parser \"%s.%s\""),
4175+
nspname, prsname);
41744176
else
4175-
sprintf(title, _("Text search parser \"%s\""), prsname);
4176-
myopt.title = title;
4177+
printfPQExpBuffer(&title, _("Text search parser \"%s\""), prsname);
4178+
myopt.title = title.data;
41774179
myopt.footers = NULL;
41784180
myopt.topt.default_footer = false;
41794181
myopt.translate_header = true;
@@ -4202,10 +4204,11 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
42024204

42034205
myopt.nullPrint = NULL;
42044206
if (nspname)
4205-
sprintf(title, _("Token types for parser \"%s.%s\""), nspname, prsname);
4207+
printfPQExpBuffer(&title, _("Token types for parser \"%s.%s\""),
4208+
nspname, prsname);
42064209
else
4207-
sprintf(title, _("Token types for parser \"%s\""), prsname);
4208-
myopt.title = title;
4210+
printfPQExpBuffer(&title, _("Token types for parser \"%s\""), prsname);
4211+
myopt.title = title.data;
42094212
myopt.footers = NULL;
42104213
myopt.topt.default_footer = true;
42114214
myopt.translate_header = true;
@@ -4214,6 +4217,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
42144217

42154218
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
42164219

4220+
termPQExpBuffer(&title);
42174221
PQclear(res);
42184222
return true;
42194223
}
@@ -5004,7 +5008,7 @@ listOneExtensionContents(const char *extname, const char *oid)
50045008
{
50055009
PQExpBufferData buf;
50065010
PGresult *res;
5007-
char title[1024];
5011+
PQExpBufferData title;
50085012
printQueryOpt myopt = pset.popt;
50095013

50105014
initPQExpBuffer(&buf);
@@ -5022,12 +5026,14 @@ listOneExtensionContents(const char *extname, const char *oid)
50225026
return false;
50235027

50245028
myopt.nullPrint = NULL;
5025-
snprintf(title, sizeof(title), _("Objects in extension \"%s\""), extname);
5026-
myopt.title = title;
5029+
initPQExpBuffer(&title);
5030+
printfPQExpBuffer(&title, _("Objects in extension \"%s\""), extname);
5031+
myopt.title = title.data;
50275032
myopt.translate_header = true;
50285033

50295034
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
50305035

5036+
termPQExpBuffer(&title);
50315037
PQclear(res);
50325038
return true;
50335039
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy