MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestReadMessageValid

Function TestReadMessageValid

server/wire/protocol_test.go:130–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128 }
129}
130
131// Regression test: a startup parameter whose final value lacks a trailing NUL
132// must NOT panic. The value-scan guard used `valEnd > len(data)`, so an
133// unterminated final value left valEnd == len(data), fell through to
134// data[valEnd+1:] == data[len(data)+1:], and panicked with "slice bounds out
135// of range". This is parsed PRE-AUTH on attacker-controlled bytes, so a panic
136// crashes the whole shared control-plane process. The fix (`valEnd >=`) breaks
137// out, returning the parameters parsed so far without error.
138func TestReadStartupMessageUnterminatedValue(t *testing.T) {
139 // v3.0 protocol version (196608 = 0x00030000) + "user\0X" with no trailing NUL.
140 body := append([]byte{0x00, 0x03, 0x00, 0x00}, []byte("user\x00X")...)
141 msg := buildRawStartup(int32(len(body)+4), body)
142
143 // Must not panic.
144 startup, err := ReadStartupMessage(bytes.NewReader(msg))
145 if err != nil {

Callers

nothing calls this directly

Calls 2

WriteMessageFunction · 0.85
ReadMessageFunction · 0.70

Tested by

no test coverage detected