]> granicus.if.org Git - postgresql/commitdiff
Get rid of unsafe sprintf and snprintf usages. Per compiler warnings.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 May 2010 00:32:21 +0000 (00:32 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 May 2010 00:32:21 +0000 (00:32 +0000)
contrib/pg_upgrade/controldata.c
contrib/pg_upgrade/info.c
contrib/pg_upgrade/server.c

index ccf7a36c9da7d430f2bc881164ebb50795aa93d1..78d62c76f4d0262361ae0d44de203e72dc9acc85 100644 (file)
@@ -62,10 +62,10 @@ get_control_data(migratorContext *ctx, ClusterInfo *cluster, bool live_check)
 #else
        SetEnvironmentVariableA("LANG", "C");
 #endif
-       sprintf(cmd, SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
-                       cluster->bindir,
-                       live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
-                       cluster->pgdata);
+       snprintf(cmd, sizeof(cmd), SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
+                        cluster->bindir,
+                        live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
+                        cluster->pgdata);
        fflush(stdout);
        fflush(stderr);
 
index 2b0bba6170b611a637b7a7ae58a968aea0bcf8d1..75a29e3d8f6ff687edfdfdda39388d5412b5b9ff 100644 (file)
@@ -362,10 +362,10 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
                curr->reloid = atol(PQgetvalue(res, relnum, i_oid));
 
                nspname = PQgetvalue(res, relnum, i_nspname);
-               snprintf(curr->nspname, sizeof(curr->nspname), nspname);
+               strlcpy(curr->nspname, nspname, sizeof(curr->nspname));
 
                relname = PQgetvalue(res, relnum, i_relname);
-               snprintf(curr->relname, sizeof(curr->relname), relname);
+               strlcpy(curr->relname, relname, sizeof(curr->relname));
 
                curr->relfilenode = atol(PQgetvalue(res, relnum, i_relfilenode));
                curr->toastrelid = atol(PQgetvalue(res, relnum, i_reltoastrelid));
@@ -374,7 +374,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
                /* if no table tablespace, use the database tablespace */
                if (strlen(tblspace) == 0)
                        tblspace = dbinfo->db_tblspace;
-               snprintf(curr->tablespace, sizeof(curr->tablespace), "%s", tblspace);
+               strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
        }
        PQclear(res);
 
index 15f4c5f07f98513d295308f1fb13d28792bb84ad..96a72b6876426f3f2de946fbd8f5565fad3c6626 100644 (file)
@@ -178,10 +178,11 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
        }
 
        /* use -l for Win32 */
-       sprintf(cmd, SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
-       "-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
-                       "start >> \"%s\" 2>&1" SYSTEMQUOTE,
-                       bindir, ctx->logfile, datadir, port, ctx->logfile);
+       snprintf(cmd, sizeof(cmd),
+                        SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
+                        "-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
+                        "start >> \"%s\" 2>&1" SYSTEMQUOTE,
+                        bindir, ctx->logfile, datadir, port, ctx->logfile);
        exec_prog(ctx, true, "%s", cmd);
 
        /* wait for the server to start properly */