Skip to content

Commit 83f4e80

Browse files
author
Michael Paquier
committed
Always return an error in case of incorrect backup mode
Some code paths allowed an invalid backup mode to be passed, something rather crazy as they directly depended on that...
1 parent 9ecd5ac commit 83f4e80

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

catalog.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ catalog_read_ini(const char *path)
492492

493493
if (backup_mode)
494494
{
495-
backup->backup_mode = parse_backup_mode(backup_mode, WARNING);
495+
backup->backup_mode = parse_backup_mode(backup_mode);
496496
free(backup_mode);
497497
}
498498

@@ -545,12 +545,14 @@ catalog_read_ini(const char *path)
545545
}
546546

547547
BackupMode
548-
parse_backup_mode(const char *value, int elevel)
548+
parse_backup_mode(const char *value)
549549
{
550550
const char *v = value;
551551
size_t len;
552552

553-
while (IsSpace(*v)) { v++; }
553+
/* Skip all spaces detected */
554+
while (IsSpace(*v))
555+
v++;
554556
len = strlen(v);
555557

556558
if (len > 0 && pg_strncasecmp("full", v, len) == 0)
@@ -560,7 +562,8 @@ parse_backup_mode(const char *value, int elevel)
560562
else if (len > 0 && pg_strncasecmp("archive", v, len) == 0)
561563
return BACKUP_MODE_ARCHIVE;
562564

563-
elog(elevel, _("invalid backup-mode \"%s\""), value);
565+
/* Backup mode is invalid, so leave with an error */
566+
elog(ERROR_ARGS, _("invalid backup-mode \"%s\""), value);
564567
return BACKUP_MODE_INVALID;
565568
}
566569

pg_rman.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,5 @@ if(!IsValidTime(tm)){
330330
static void
331331
opt_backup_mode(pgut_option *opt, const char *arg)
332332
{
333-
current.backup_mode = parse_backup_mode(arg, ERROR_ARGS);
333+
current.backup_mode = parse_backup_mode(arg);
334334
}

pg_rman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ extern const char *pgdata_exclude[];
230230

231231
/* in backup.c */
232232
extern int do_backup(pgBackupOption bkupopt);
233-
extern BackupMode parse_backup_mode(const char *value, int elevel);
233+
extern BackupMode parse_backup_mode(const char *value);
234234
extern void check_server_version(void);
235235
extern bool fileExists(const char *path);
236236

0 commit comments

Comments
 (0)