Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
infn-ke opened this issue Apr 23, 2024 · 0 comments
Open

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

infn-ke opened this issue Apr 23, 2024 · 0 comments
Labels

Comments

@infn-ke
Copy link

infn-ke commented Apr 23, 2024

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.

@infn-ke infn-ke added the bug label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant