Skip to content

[BUG] TCPTransport::underlyingReceive not signal safe #423

Open
@infn-ke

Description

Describe the bug

The tcp transport class (TCPTransport) is not signal safe in underlyingReceive. It omits checking the errno value to see if the call was interrupted by a signal. Below is simple patch trying to address this issue.

diff --git a/erpc_c/transports/erpc_tcp_transport.cpp b/erpc_c/transports/erpc_tcp_transport.cpp
index 9712ce6..f755231 100644
--- a/erpc_c/transports/erpc_tcp_transport.cpp
+++ b/erpc_c/transports/erpc_tcp_transport.cpp
@@ -306,7 +306,6 @@ erpc_status_t TCPTransport::close(bool stopServer)
 erpc_status_t TCPTransport::underlyingReceive(uint8_t *data, uint32_t size)
 {
     ssize_t length;
-    erpc_status_t status = kErpcStatus_Success;
 
     // Block until we have a valid connection.
 #if defined(__MINGW32__)
@@ -334,23 +333,22 @@ erpc_status_t TCPTransport::underlyingReceive(uint8_t *data, uint32_t size)
             size -= length;
             data += length;
         }
+        else if (length == 0)
+        {
+            // close socket, not server
+            close(false);
+            return kErpcStatus_ConnectionClosed;
+        }
         else
         {
-            if (length == 0)
-            {
-                // close socket, not server
-                close(false);
-                status = kErpcStatus_ConnectionClosed;
-            }
-            else
+            if (errno != EINTR && errno != EAGAIN)
             {
-                status = kErpcStatus_ReceiveFailed;
+                return kErpcStatus_ReceiveFailed;
             }
-            break;
         }
     }
 
-    return status;
+    return kErpcStatus_Success;
 }
 
 erpc_status_t TCPTransport::underlyingSend(const uint8_t *data, uint32_t size)

To Reproduce

Send a signal to the program while waiting for a erpc response.

Expected behavior

erpc library should be signal safe.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions