Skip to content

Commit 39f7da0

Browse files
committed
streamclient: fix panic in sslinline parsing
If sslmode=disable, the underlying library returns a nil TLSConfig. Fixes #155224 Release note (bug fix): Fix a bug that would result in a node crash if a PCR or LDR URI used sslinline=true with sslmode=disable.
1 parent 44eef4b commit 39f7da0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/crosscluster/streamclient/client_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,23 @@ SXy25ZnLdt1xMg==
387387
require.NoError(t, err)
388388
})
389389

390+
t.Run("all valid certs but disabled", func(t *testing.T) {
391+
query := url.Values{}
392+
query.Add(SslInlineURLParam, "true")
393+
query.Add(sslCertURLParam, validCert)
394+
query.Add(sslKeyURLParam, validKey)
395+
query.Add(sslRootCertURLParam, validCert)
396+
query.Add(sslModeURLParam, "disable")
397+
398+
remote := url.URL{
399+
Scheme: "postgresql",
400+
Host: "localhost:26257",
401+
RawQuery: query.Encode(),
402+
}
403+
_, err := setupPGXConfig(remote, options{})
404+
require.NoError(t, err)
405+
})
406+
390407
t.Run("invalid cert", func(t *testing.T) {
391408
query := url.Values{}
392409
query.Add(SslInlineURLParam, "true")

pkg/crosscluster/streamclient/pgconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func uriWithInlineTLSCertsRemoved(remote url.URL) (url.URL, *tlsCerts, error) {
138138
}
139139

140140
func (c *tlsCerts) addTLSCertsToConfig(tlsConfig *tls.Config) {
141-
if c == nil {
141+
if c == nil || tlsConfig == nil {
142142
return
143143
}
144144

0 commit comments

Comments
 (0)