diff --git a/contrib/pg_archivecleanup/pg_archivecleanup.c b/contrib/pg_archivecleanup/pg_archivecleanup.c index ee7cba6b707..c21c0dac6d1 100644 --- a/contrib/pg_archivecleanup/pg_archivecleanup.c +++ b/contrib/pg_archivecleanup/pg_archivecleanup.c @@ -41,7 +41,7 @@ char *additional_ext = NULL; /* Extension to remove from filenames */ char *archiveLocation; /* where to find the archive? */ char *restartWALFileName; /* the file from which we can restart restore */ -char WALFilePath[MAXPGPATH]; /* the file path including archive */ +char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */ char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we * want to remain in * archive */ @@ -144,7 +144,7 @@ CleanupPriorWALFiles(void) * extension that might have been chopped off before testing * the sequence. */ - snprintf(WALFilePath, MAXPGPATH, "%s/%s", + snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s", archiveLocation, xlde->d_name); if (dryrun) diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c index 8be544bf70d..2fb9b2bcac0 100644 --- a/contrib/pg_standby/pg_standby.c +++ b/contrib/pg_standby/pg_standby.c @@ -66,7 +66,7 @@ char *xlogFilePath; /* where we are going to restore to */ char *nextWALFileName; /* the file we need to get from archive */ char *restartWALFileName; /* the file from which we can restart restore */ char *priorWALFileName; /* the file we need to get from archive */ -char WALFilePath[MAXPGPATH]; /* the file path including archive */ +char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */ char restoreCommand[MAXPGPATH]; /* run this to restore */ char exclusiveCleanupFileName[MAXPGPATH]; /* the file we need to * get from archive */ @@ -277,9 +277,9 @@ CustomizableCleanupPriorWALFiles(void) strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0) { #ifdef WIN32 - snprintf(WALFilePath, MAXPGPATH, "%s\\%s", archiveLocation, xlde->d_name); + snprintf(WALFilePath, sizeof(WALFilePath), "%s\\%s", archiveLocation, xlde->d_name); #else - snprintf(WALFilePath, MAXPGPATH, "%s/%s", archiveLocation, xlde->d_name); + snprintf(WALFilePath, sizeof(WALFilePath), "%s/%s", archiveLocation, xlde->d_name); #endif if (debug) diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c index 4cc9782da0f..e39a44ab429 100644 --- a/contrib/pg_upgrade/relfilenode.c +++ b/contrib/pg_upgrade/relfilenode.c @@ -215,8 +215,8 @@ transfer_relfile(pageCnvCtx *pageConverter, FileNameMap *map, const char *type_suffix) { const char *msg; - char old_file[MAXPGPATH]; - char new_file[MAXPGPATH]; + char old_file[MAXPGPATH * 3]; + char new_file[MAXPGPATH * 3]; int fd; int segno; char extent_suffix[65]; diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 2d514eca104..33af2f62914 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3099,7 +3099,7 @@ CleanupBackupHistory(void) { DIR *xldir; struct dirent *xlde; - char path[MAXPGPATH]; + char path[MAXPGPATH + sizeof(XLOGDIR)]; xldir = AllocateDir(XLOGDIR); if (xldir == NULL) @@ -3120,7 +3120,7 @@ CleanupBackupHistory(void) ereport(DEBUG2, (errmsg("removing transaction log backup history file \"%s\"", xlde->d_name))); - snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name); + snprintf(path, sizeof(path), XLOGDIR "/%s", xlde->d_name); unlink(path); XLogArchiveCleanup(xlde->d_name); } diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index f9de610434f..fc8709bbc1e 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -559,7 +559,7 @@ pgstat_reset_remove_files(const char *directory) { DIR *dir; struct dirent *entry; - char fname[MAXPGPATH]; + char fname[MAXPGPATH * 2]; dir = AllocateDir(directory); while ((entry = ReadDir(dir, directory)) != NULL) @@ -589,7 +589,7 @@ pgstat_reset_remove_files(const char *directory) strcmp(entry->d_name + nchars, "stat") != 0) continue; - snprintf(fname, MAXPGPATH, "%s/%s", directory, + snprintf(fname, sizeof(fname), "%s/%s", directory, entry->d_name); unlink(fname); } diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 4f4686d9253..587d7d61c2a 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -122,7 +122,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) /* Collect information about all tablespaces */ while ((de = ReadDir(tblspcdir, "pg_tblspc")) != NULL) { - char fullpath[MAXPGPATH]; + char fullpath[MAXPGPATH + 10]; char linkpath[MAXPGPATH]; char *relpath = NULL; int rllen; @@ -831,7 +831,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces) { DIR *dir; struct dirent *de; - char pathbuf[MAXPGPATH]; + char pathbuf[MAXPGPATH * 2]; struct stat statbuf; int64 size = 0; @@ -873,7 +873,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces) "and should not be used. " "Try taking another online backup."))); - snprintf(pathbuf, MAXPGPATH, "%s/%s", path, de->d_name); + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name); /* Skip postmaster.pid and postmaster.opts in the data directory */ if (strcmp(pathbuf, "./postmaster.pid") == 0 || diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c index 427a0df7182..6460410df7b 100644 --- a/src/backend/storage/file/copydir.c +++ b/src/backend/storage/file/copydir.c @@ -38,8 +38,8 @@ copydir(char *fromdir, char *todir, bool recurse) { DIR *xldir; struct dirent *xlde; - char fromfile[MAXPGPATH]; - char tofile[MAXPGPATH]; + char fromfile[MAXPGPATH * 2]; + char tofile[MAXPGPATH * 2]; if (mkdir(todir, S_IRWXU) != 0) ereport(ERROR, @@ -63,8 +63,8 @@ copydir(char *fromdir, char *todir, bool recurse) strcmp(xlde->d_name, "..") == 0) continue; - snprintf(fromfile, MAXPGPATH, "%s/%s", fromdir, xlde->d_name); - snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name); + snprintf(fromfile, sizeof(fromfile), "%s/%s", fromdir, xlde->d_name); + snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name); if (lstat(fromfile, &fst) < 0) ereport(ERROR, @@ -103,7 +103,7 @@ copydir(char *fromdir, char *todir, bool recurse) strcmp(xlde->d_name, "..") == 0) continue; - snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name); + snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name); /* * We don't need to sync subdirectories here since the recursive diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index c269436800b..0c8dd78bacd 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -2460,7 +2460,7 @@ CleanupTempFiles(bool isProcExit) void RemovePgTempFiles(void) { - char temp_path[MAXPGPATH]; + char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY) + sizeof(PG_TEMP_FILES_DIR)]; DIR *spc_dir; struct dirent *spc_de; @@ -2508,7 +2508,7 @@ RemovePgTempFilesInDir(const char *tmpdirname) { DIR *temp_dir; struct dirent *temp_de; - char rm_path[MAXPGPATH]; + char rm_path[MAXPGPATH * 2]; temp_dir = AllocateDir(tmpdirname); if (temp_dir == NULL) @@ -2549,7 +2549,7 @@ RemovePgTempRelationFiles(const char *tsdirname) { DIR *ts_dir; struct dirent *de; - char dbspace_path[MAXPGPATH]; + char dbspace_path[MAXPGPATH * 2]; ts_dir = AllocateDir(tsdirname); if (ts_dir == NULL) @@ -2590,7 +2590,7 @@ RemovePgTempRelationFilesInDbspace(const char *dbspacedirname) { DIR *dbspace_dir; struct dirent *de; - char rm_path[MAXPGPATH]; + char rm_path[MAXPGPATH * 2]; dbspace_dir = AllocateDir(dbspacedirname); if (dbspace_dir == NULL) @@ -2777,7 +2777,7 @@ walkdir(const char *path, while ((de = ReadDirExtended(dir, path, elevel)) != NULL) { - char subpath[MAXPGPATH]; + char subpath[MAXPGPATH * 2]; struct stat fst; int sret; @@ -2787,7 +2787,7 @@ walkdir(const char *path, strcmp(de->d_name, "..") == 0) continue; - snprintf(subpath, MAXPGPATH, "%s/%s", path, de->d_name); + snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name); if (process_symlinks) sret = stat(subpath, &fst); diff --git a/src/backend/storage/file/reinit.c b/src/backend/storage/file/reinit.c index 93172b0dddc..3c8742cc29f 100644 --- a/src/backend/storage/file/reinit.c +++ b/src/backend/storage/file/reinit.c @@ -48,7 +48,7 @@ typedef struct void ResetUnloggedRelations(int op) { - char temp_path[MAXPGPATH]; + char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)]; DIR *spc_dir; struct dirent *spc_de; MemoryContext tmpctx, @@ -106,7 +106,7 @@ ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op) { DIR *ts_dir; struct dirent *de; - char dbspace_path[MAXPGPATH]; + char dbspace_path[MAXPGPATH * 2]; ts_dir = AllocateDir(tsdirname); if (ts_dir == NULL) @@ -147,7 +147,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op) { DIR *dbspace_dir; struct dirent *de; - char rm_path[MAXPGPATH]; + char rm_path[MAXPGPATH * 2]; /* Caller must specify at least one operation. */ Assert((op & (UNLOGGED_RELATION_CLEANUP | UNLOGGED_RELATION_INIT)) != 0); @@ -310,7 +310,7 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op) ForkNumber forkNum; int oidchars; char oidbuf[OIDCHARS + 1]; - char srcpath[MAXPGPATH]; + char srcpath[MAXPGPATH * 2]; char dstpath[MAXPGPATH]; /* Skip anything that doesn't look like a relation data file. */ diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 3d32dcad8d1..6c69a01294a 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -39,7 +39,7 @@ db_dir_size(const char *path) int64 dirsize = 0; struct dirent *direntry; DIR *dirdesc; - char filename[MAXPGPATH]; + char filename[MAXPGPATH * 2]; dirdesc = AllocateDir(path); @@ -56,7 +56,7 @@ db_dir_size(const char *path) strcmp(direntry->d_name, "..") == 0) continue; - snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name); + snprintf(filename, sizeof(filename), "%s/%s", path, direntry->d_name); if (stat(filename, &fst) < 0) { @@ -84,7 +84,7 @@ calculate_database_size(Oid dbOid) DIR *dirdesc; struct dirent *direntry; char dirpath[MAXPGPATH]; - char pathname[MAXPGPATH]; + char pathname[MAXPGPATH + 12 + sizeof(TABLESPACE_VERSION_DIRECTORY)]; AclResult aclresult; /* User must have connect privilege for target database */ @@ -96,7 +96,7 @@ calculate_database_size(Oid dbOid) /* Shared storage in pg_global is not counted */ /* Include pg_default storage */ - snprintf(pathname, MAXPGPATH, "base/%u", dbOid); + snprintf(pathname, sizeof(pathname), "base/%u", dbOid); totalsize = db_dir_size(pathname); /* Scan the non-default tablespaces */ @@ -116,7 +116,7 @@ calculate_database_size(Oid dbOid) strcmp(direntry->d_name, "..") == 0) continue; - snprintf(pathname, MAXPGPATH, "pg_tblspc/%s/%s/%u", + snprintf(pathname, sizeof(pathname), "pg_tblspc/%s/%s/%u", direntry->d_name, TABLESPACE_VERSION_DIRECTORY, dbOid); totalsize += db_dir_size(pathname); } @@ -164,7 +164,7 @@ static int64 calculate_tablespace_size(Oid tblspcOid) { char tblspcPath[MAXPGPATH]; - char pathname[MAXPGPATH]; + char pathname[MAXPGPATH * 2]; int64 totalsize = 0; DIR *dirdesc; struct dirent *direntry; @@ -206,7 +206,7 @@ calculate_tablespace_size(Oid tblspcOid) strcmp(direntry->d_name, "..") == 0) continue; - snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name); + snprintf(pathname, sizeof(pathname), "%s/%s", tblspcPath, direntry->d_name); if (stat(pathname, &fst) < 0) { diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 79b0993b81f..799e9aebe92 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -4869,7 +4869,7 @@ RelationCacheInitFileRemove(void) const char *tblspcdir = "pg_tblspc"; DIR *dir; struct dirent *de; - char path[MAXPGPATH]; + char path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)]; /* * We zap the shared cache file too. In theory it can't get out of sync @@ -4911,7 +4911,7 @@ RelationCacheInitFileRemoveInDir(const char *tblspcpath) { DIR *dir; struct dirent *de; - char initfilename[MAXPGPATH]; + char initfilename[MAXPGPATH * 2]; /* Scan the tablespace directory to find per-database directories */ dir = AllocateDir(tblspcpath); diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 526b5bb8fc7..fcb5f180b23 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -2013,7 +2013,7 @@ setup_formatted_log_time(void) { struct timeval tv; pg_time_t stamp_time; - char msbuf[8]; + char msbuf[13]; gettimeofday(&tv, NULL); stamp_time = (pg_time_t) tv.tv_sec; diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 3bf42423313..1cdf6242879 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1155,7 +1155,7 @@ XactHasExportedSnapshots(void) void DeleteAllExportedSnapshotFiles(void) { - char buf[MAXPGPATH]; + char buf[MAXPGPATH + sizeof(SNAPSHOT_EXPORT_DIR)]; DIR *s_dir; struct dirent *s_de; @@ -1176,7 +1176,7 @@ DeleteAllExportedSnapshotFiles(void) strcmp(s_de->d_name, "..") == 0) continue; - snprintf(buf, MAXPGPATH, SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name); + snprintf(buf, sizeof(buf), SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name); /* Again, unlink failure is not worthy of FATAL */ if (unlink(buf)) elog(LOG, "could not unlink file \"%s\": %m", buf); diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 07890d67bed..47a4c617769 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -556,7 +556,7 @@ walkdir(const char *path, while (errno = 0, (de = readdir(dir)) != NULL) { - char subpath[MAXPGPATH]; + char subpath[MAXPGPATH * 2]; struct stat fst; int sret; @@ -564,7 +564,7 @@ walkdir(const char *path, strcmp(de->d_name, "..") == 0) continue; - snprintf(subpath, MAXPGPATH, "%s/%s", path, de->d_name); + snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name); if (process_symlinks) sret = stat(subpath, &fst); diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index 240544f6f9b..8430d784500 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -178,7 +178,7 @@ FindStreamingStart(uint32 *tli) if (!ispartial) { struct stat statbuf; - char fullpath[MAXPGPATH]; + char fullpath[MAXPGPATH * 2]; snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name); if (stat(fullpath, &statbuf) != 0) diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 8a066b46012..cc6b2540a89 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -836,7 +836,7 @@ KillExistingXLOG(void) { DIR *xldir; struct dirent *xlde; - char path[MAXPGPATH]; + char path[MAXPGPATH + sizeof(XLOGDIR)]; xldir = opendir(XLOGDIR); if (xldir == NULL) @@ -851,7 +851,7 @@ KillExistingXLOG(void) if (strlen(xlde->d_name) == 24 && strspn(xlde->d_name, "0123456789ABCDEF") == 24) { - snprintf(path, MAXPGPATH, "%s/%s", XLOGDIR, xlde->d_name); + snprintf(path, sizeof(path), "%s/%s", XLOGDIR, xlde->d_name); if (unlink(path) < 0) { fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"), @@ -889,11 +889,11 @@ KillExistingXLOG(void) static void KillExistingArchiveStatus(void) { +#define ARCHSTATDIR XLOGDIR "/archive_status" + DIR *xldir; struct dirent *xlde; - char path[MAXPGPATH]; - -#define ARCHSTATDIR XLOGDIR "/archive_status" + char path[MAXPGPATH + sizeof(ARCHSTATDIR)]; xldir = opendir(ARCHSTATDIR); if (xldir == NULL) @@ -909,7 +909,7 @@ KillExistingArchiveStatus(void) (strcmp(xlde->d_name + 24, ".ready") == 0 || strcmp(xlde->d_name + 24, ".done") == 0)) { - snprintf(path, MAXPGPATH, "%s/%s", ARCHSTATDIR, xlde->d_name); + snprintf(path, sizeof(path), "%s/%s", ARCHSTATDIR, xlde->d_name); if (unlink(path) < 0) { fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"), diff --git a/src/timezone/pgtz.c b/src/timezone/pgtz.c index d44458ae51a..667fda3a637 100644 --- a/src/timezone/pgtz.c +++ b/src/timezone/pgtz.c @@ -437,7 +437,7 @@ pg_tzenumerate_next(pg_tzenum *dir) while (dir->depth >= 0) { struct dirent *direntry; - char fullname[MAXPGPATH]; + char fullname[MAXPGPATH * 2]; struct stat statbuf; direntry = ReadDir(dir->dirdesc[dir->depth], dir->dirname[dir->depth]); @@ -454,7 +454,7 @@ pg_tzenumerate_next(pg_tzenum *dir) if (direntry->d_name[0] == '.') continue; - snprintf(fullname, MAXPGPATH, "%s/%s", + snprintf(fullname, sizeof(fullname), "%s/%s", dir->dirname[dir->depth], direntry->d_name); if (stat(fullname, &statbuf) != 0) ereport(ERROR,