diff --git a/connection.go b/connection.go index 82c56ea..60f9a6b 100644 --- a/connection.go +++ b/connection.go @@ -300,7 +300,7 @@ func (c *Connection) close() error { } } - if c.Opts.ConnectionClosedHandlers != nil && len(c.Opts.ConnectionClosedHandlers) > 0 { + if len(c.Opts.ConnectionClosedHandlers) > 0 { for _, handler := range c.Opts.ConnectionClosedHandlers { go handler(c) } @@ -454,7 +454,7 @@ func (c *Connection) Send(message *iso8583.Message, options ...Option) (*iso8583 return resp, err } -func (c *Connection) writeMessage(w io.Writer, message *iso8583.Message) error { +func (c *Connection) writeMessage(message *iso8583.Message) error { if c.Opts.MessageWriter != nil { err := c.Opts.MessageWriter.WriteMessage(c.conn, message) if err != nil { @@ -577,7 +577,7 @@ func (c *Connection) writeLoop() { c.pendingRequestsMu.Unlock() } - err = c.writeMessage(c.conn, req.message) + err = c.writeMessage(req.message) if err != nil { c.handleError(fmt.Errorf("writing message: %w", err)) diff --git a/connection_test.go b/connection_test.go index 9aaa02f..3b501b0 100644 --- a/connection_test.go +++ b/connection_test.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "math" "net" "net/http" "sync" @@ -1348,6 +1349,10 @@ func (m *messageIO) WriteMessage(w io.Writer, message *iso8583.Message) error { } // create header with message length + if len(rawMessage) > math.MaxUint16 { + return fmt.Errorf("message length is out of uint16 range: %d", len(rawMessage)) + } + //nolint:gosec // disable G115 as it's a false positive h := header{ Length: uint16(len(rawMessage)), } diff --git a/pool_test.go b/pool_test.go index 8fd0dea..11093d4 100644 --- a/pool_test.go +++ b/pool_test.go @@ -92,6 +92,7 @@ func TestPool(t *testing.T) { // Then pool builds and connects connections to all servers require.Eventually(t, func() bool { // we expect connectionsCnt counter to be incremented by both servers + //nolint:gosec // disable G115 return atomic.LoadInt32(&connectionsCnt) == int32(serversToStart) }, 500*time.Millisecond, 50*time.Millisecond, "%d expected connections established, but got %d", serversToStart, atomic.LoadInt32(&connectionsCnt))