Skip to content

Commit 8eac397

Browse files
committed
Get rid of unsafe sprintf and snprintf usages. Per compiler warnings.
1 parent adf6b8e commit 8eac397

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

contrib/pg_upgrade/controldata.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
6262
#else
6363
SetEnvironmentVariableA("LANG", "C");
6464
#endif
65-
sprintf(cmd, SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
66-
cluster->bindir,
67-
live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
68-
cluster->pgdata);
65+
snprintf(cmd, sizeof(cmd), SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
66+
cluster->bindir,
67+
live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
68+
cluster->pgdata);
6969
fflush(stdout);
7070
fflush(stderr);
7171

contrib/pg_upgrade/info.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
362362
curr->reloid = atol(PQgetvalue(res, relnum, i_oid));
363363

364364
nspname = PQgetvalue(res, relnum, i_nspname);
365-
snprintf(curr->nspname, sizeof(curr->nspname), nspname);
365+
strlcpy(curr->nspname, nspname, sizeof(curr->nspname));
366366

367367
relname = PQgetvalue(res, relnum, i_relname);
368-
snprintf(curr->relname, sizeof(curr->relname), relname);
368+
strlcpy(curr->relname, relname, sizeof(curr->relname));
369369

370370
curr->relfilenode = atol(PQgetvalue(res, relnum, i_relfilenode));
371371
curr->toastrelid = atol(PQgetvalue(res, relnum, i_reltoastrelid));
@@ -374,7 +374,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
374374
/* if no table tablespace, use the database tablespace */
375375
if (strlen(tblspace) == 0)
376376
tblspace = dbinfo->db_tblspace;
377-
snprintf(curr->tablespace, sizeof(curr->tablespace), "%s", tblspace);
377+
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
378378
}
379379
PQclear(res);
380380

contrib/pg_upgrade/server.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
178178
}
179179

180180
/* use -l for Win32 */
181-
sprintf(cmd, SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
182-
"-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
183-
"start >> \"%s\" 2>&1" SYSTEMQUOTE,
184-
bindir, ctx->logfile, datadir, port, ctx->logfile);
181+
snprintf(cmd, sizeof(cmd),
182+
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
183+
"-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
184+
"start >> \"%s\" 2>&1" SYSTEMQUOTE,
185+
bindir, ctx->logfile, datadir, port, ctx->logfile);
185186
exec_prog(ctx, true, "%s", cmd);
186187

187188
/* wait for the server to start properly */

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