Skip to content

Commit 29fa81c

Browse files
authored
Fix panic when parsing backup options with extra space
There existed a condition where checking for new backup options in the "pgo backup" command could cause a panic. This resolves the issue both by adding a guard on the array and trimming whitespace.
1 parent cb89f0b commit 29fa81c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/apiserver/backupoptions/backupoptionsutil.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type backupOptions interface {
3636
// and restore utilities supported by pgo (e.g. pg_dump, pg_restore, pgBackRest, etc.)
3737
func ValidateBackupOpts(backupOpts string, request interface{}) error {
3838
// some quick checks to make sure backup opts string is valid and should be processed and validated
39-
if strings.TrimSpace(backupOpts) == "" {
39+
backupOpts = strings.TrimSpace(backupOpts)
40+
if backupOpts == "" {
4041
return nil
4142
} else if !strings.HasPrefix(strings.TrimSpace(backupOpts), "-") &&
4243
!strings.HasPrefix(strings.TrimSpace(backupOpts), "--") {
@@ -112,7 +113,7 @@ func parseBackupOpts(backupOpts string) []string {
112113
var newField string
113114
for i, c := range backupOpts {
114115
// if another option is found, add current option to newFields array
115-
if !(c == ' ' && backupOpts[i+1] == '-') {
116+
if !(c == ' ' && i+1 < len(backupOpts) && backupOpts[i+1] == '-') {
116117
newField = newField + string(c)
117118
}
118119

0 commit comments

Comments
 (0)