(t *testing.T)
| 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. |
| 138 | func 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 { |
nothing calls this directly
no test coverage detected