Add additional safety check against invalid backup label file

It was already checking for invalid data after "BACKUP FROM", but
would possibly crash if "BACKUP FROM" was missing altogether.

found by Coverity
This commit is contained in:
Peter Eisentraut 2012-03-14 22:41:50 +02:00
parent acfaa596cc
commit e684ab5e1e
1 changed files with 1 additions and 1 deletions

View File

@ -9481,7 +9481,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive)
* during the backup.
*/
ptr = strstr(remaining, "BACKUP FROM:");
if (sscanf(ptr, "BACKUP FROM: %19s\n", backupfrom) != 1)
if (!ptr || sscanf(ptr, "BACKUP FROM: %19s\n", backupfrom) != 1)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));