diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 330e058c5f..b1c4896c90 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8727,14 +8727,12 @@ 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)); - /* * Mark backup active in shared memory. We must do full-page WAL writes * during an on-line backup even if not doing so at other times, because diff --git a/src/include/access/xlogbackup.h b/src/include/access/xlogbackup.h index c30d4a5991..ec4d7614c2 100644 --- a/src/include/access/xlogbackup.h +++ b/src/include/access/xlogbackup.h @@ -21,8 +21,8 @@ typedef struct BackupState { /* Fields saved at backup start */ - /* Backup label name one extra byte for null-termination */ - char name[MAXPGPATH + 1]; + /* Backup label name */ + char name[MAXPGPATH]; XLogRecPtr startpoint; /* backup start WAL location */ TimeLineID starttli; /* backup start TLI */ XLogRecPtr checkpointloc; /* last checkpoint location */