Improve error handling in packet reader - check error before processing

Only clear reserved bytes if read was successful (err == nil). This prevents
processing invalid data when conn.Read() returns an error.

Code review feedback addressed.

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-09 11:28:43 +00:00
parent ea3badc641
commit cc36c1b5bf

View File

@@ -183,7 +183,8 @@ func (bind *netBindClient) connectTo(endpoint *netEndpoint) error {
buf := make([]byte, maxPacketSize) buf := make([]byte, maxPacketSize)
n, err := conn.Read(buf) n, err := conn.Read(buf)
if n > 3 { // Only process data if we successfully read something
if err == nil && n > 3 {
// Clear reserved bytes // Clear reserved bytes
buf[1] = 0 buf[1] = 0
buf[2] = 0 buf[2] = 0