From 8cf4567f3cca780fbee5c9f1601997c4d3ac34a4 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sun, 21 Apr 2024 16:47:21 +0530 Subject: [PATCH 1/3] agnhost/netexec: handle nil pointer dereference for SCTP server If the client immediately closes connection after SCTP handshake, the remote-addr fetched by SCTP server can be nil, causing the server to crash. Signed-off-by: Daman Arora --- test/images/agnhost/netexec/netexec.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/images/agnhost/netexec/netexec.go b/test/images/agnhost/netexec/netexec.go index a63054f7771..f1e2e62d536 100644 --- a/test/images/agnhost/netexec/netexec.go +++ b/test/images/agnhost/netexec/netexec.go @@ -693,7 +693,11 @@ func startSCTPServer(sctpPort int) { for { conn, err := listener.AcceptSCTP() assertNoError(err, fmt.Sprintf("failed accepting SCTP connections")) - clientAddress := conn.RemoteAddr().String() + remoteAddr, err := conn.SCTPRemoteAddr(0) + if err != nil { + assertNoError(err, "failed to get SCTP client remote address") + } + clientAddress := remoteAddr.String() n, err := conn.Read(buf) assertNoError(err, fmt.Sprintf("failed to read from SCTP client %s", clientAddress)) receivedText := strings.ToLower(strings.TrimSpace(string(buf[0:n]))) From 1c8799f814a7d1c00190d79ee9ced7243f1118a1 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Sun, 21 Apr 2024 17:12:26 +0530 Subject: [PATCH 2/3] agnhost/connect: send and recv data from SCTP server If the client immediately closes connection after SCTP handshake, the server will die with EOF, adding send and recv calls in the client to make sure server client handling loop exits gracefully. Signed-off-by: Daman Arora --- test/images/agnhost/connect/connect.go | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/test/images/agnhost/connect/connect.go b/test/images/agnhost/connect/connect.go index 3423549e2d0..fcb111dd276 100644 --- a/test/images/agnhost/connect/connect.go +++ b/test/images/agnhost/connect/connect.go @@ -47,12 +47,14 @@ var ( timeout time.Duration protocol string udpData string + sctpData string ) func init() { CmdConnect.Flags().DurationVar(&timeout, "timeout", time.Duration(0), "Maximum time before returning an error") CmdConnect.Flags().StringVar(&protocol, "protocol", "tcp", "The protocol to use to perform the connection, can be tcp, udp or sctp") CmdConnect.Flags().StringVar(&udpData, "udp-data", "hostname", "The UDP payload send to the server") + CmdConnect.Flags().StringVar(&sctpData, "sctp-data", "hostname", "The SCTP payload send to the server") } func main(cmd *cobra.Command, args []string) { @@ -63,7 +65,7 @@ func main(cmd *cobra.Command, args []string) { case "udp": connectUDP(dest, timeout, udpData) case "sctp": - connectSCTP(dest, timeout) + connectSCTP(dest, timeout, sctpData) default: fmt.Fprint(os.Stderr, "Unsupported protocol\n", protocol) os.Exit(1) @@ -103,7 +105,11 @@ func connectTCP(dest string, timeout time.Duration) { os.Exit(1) } -func connectSCTP(dest string, timeout time.Duration) { +func connectSCTP(dest string, timeout time.Duration, data string) { + var ( + buf = make([]byte, 1024) + conn *sctp.SCTPConn + ) addr, err := sctp.ResolveSCTPAddr("sctp", dest) if err != nil { fmt.Fprintf(os.Stderr, "DNS: %v\n", err) @@ -114,11 +120,24 @@ func connectSCTP(dest string, timeout time.Duration) { errCh := make(chan error) go func() { - conn, err := sctp.DialSCTP("sctp", nil, addr) - if err == nil { - conn.Close() + conn, err = sctp.DialSCTP("sctp", nil, addr) + if err != nil { + errCh <- err + return + } + defer func() { + errCh <- conn.Close() + }() + + if _, err = conn.Write([]byte(fmt.Sprintf("%s\n", data))); err != nil { + errCh <- err + return + } + + if _, err = conn.Read(buf); err != nil { + errCh <- err + return } - errCh <- err }() select { From ce41bc849f03ae3b0aea25457d734ed1998ac734 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Mon, 22 Apr 2024 16:29:48 +0530 Subject: [PATCH 3/3] agnhost: version bump to v2.50 Signed-off-by: Daman Arora --- test/images/agnhost/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index 6e272ad31f5..f02fc206201 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.49 +2.50