Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fbconn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ func parseKeywordValueSettings(s string) (map[string]string, error) {
}
if s[end] == '\\' {
end++
if end == len(s) {
return nil, errors.New("unterminated quoted string in connection info string")
}
}
}
if end == len(s) {
Expand Down
28 changes: 28 additions & 0 deletions fbconn/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,31 @@ func TestParseConfigEnv(t *testing.T) {
})
}
}

// A backslash as the last byte of an unterminated quoted value must be
// rejected as an unterminated string, not panic with a slice bounds error.
// The quoted-string loop advances past a backslash without bounds-checking
// the resulting index, so `='\` (and `0='\`, reached via the fbxpool path)
// previously panicked with "slice bounds out of range [:2] with length 1".
func TestParseConfigKVQuotedTrailingBackslashDoesNotPanic(t *testing.T) {
tests := []struct {
name string
connString string
}{
{name: "bare quoted trailing backslash", connString: `='\`},
{name: "quoted trailing backslash with key", connString: `0='\`},
{name: "quoted trailing backslash after value", connString: `host='a\`},
{name: "quoted trailing backslash after escaped pair", connString: `host='a\\b\`},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var err error
assert.NotPanics(t, func() {
_, err = fbconn.ParseConfig(tt.connString)
})
require.Error(t, err)
assert.Contains(t, err.Error(), "unterminated quoted string in connection info string")
})
}
}