Skip to content

Commit 76ad54b

Browse files
jkatzJonathan S. Katz
authored andcommitted
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 9f1fd42 commit 76ad54b

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
@@ -37,7 +37,8 @@ type backupOptions interface {
3737
func ValidateBackupOpts(backupOpts string, request interface{}) error {
3838

3939
// some quick checks to make sure backup opts string is valid and should be processed and validated
40-
if strings.TrimSpace(backupOpts) == "" {
40+
backupOpts = strings.TrimSpace(backupOpts)
41+
if backupOpts == "" {
4142
return nil
4243
} else if !strings.HasPrefix(strings.TrimSpace(backupOpts), "-") &&
4344
!strings.HasPrefix(strings.TrimSpace(backupOpts), "--") {
@@ -114,7 +115,7 @@ func parseBackupOpts(backupOpts string) []string {
114115
var newField string
115116
for i, c := range backupOpts {
116117
// if another option is found, add current option to newFields array
117-
if !(c == ' ' && backupOpts[i+1] == '-') {
118+
if !(c == ' ' && i+1 < len(backupOpts) && backupOpts[i+1] == '-') {
118119
newField = newField + string(c)
119120
}
120121

0 commit comments

Comments
 (0)