diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 8dcdf5a764..01ed7d1ea0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8736,13 +8736,11 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, errmsg("WAL level not sufficient for making an online backup"), errhint("\"wal_level\" must be set to \"replica\" or \"logical\" at server start."))); - if (strlen(backupidstr) > MAXPGPATH) + if (strlcpy(state->name, backupidstr, sizeof(state->name)) >= sizeof(state->name)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("backup label too long (max %d bytes)", - MAXPGPATH))); - - memcpy(state->name, backupidstr, strlen(backupidstr)); + MAXPGPATH - 1))); /* * Mark backup active in shared memory. We must do full-page WAL writes diff --git a/src/include/access/xlogbackup.h b/src/include/access/xlogbackup.h index c30d4a5991..a52345850e 100644 --- a/src/include/access/xlogbackup.h +++ b/src/include/access/xlogbackup.h @@ -21,8 +21,7 @@ typedef struct BackupState { /* Fields saved at backup start */ - /* Backup label name one extra byte for null-termination */ - char name[MAXPGPATH + 1]; + char name[MAXPGPATH];/* backup label name */ XLogRecPtr startpoint; /* backup start WAL location */ TimeLineID starttli; /* backup start TLI */ XLogRecPtr checkpointloc; /* last checkpoint location */