]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Ignore SIGPIPE if client closes connection abruptly
authorVishwa Pravin <lordvishwa123@gmail.com>
Mon, 3 Apr 2023 06:46:33 +0000 (12:16 +0530)
committerPauli <pauli@openssl.org>
Thu, 6 Apr 2023 03:41:53 +0000 (13:41 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20678)

demos/sslecho/main.c

index 0233794c4e4064b71b7ad90bf78297ac27bb796a..ca430046c494cbbca23a057223db9cbfd1201b74 100644 (file)
@@ -14,6 +14,7 @@
 #include <arpa/inet.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
+#include <signal.h>
 
 static const int server_port = 4433;
 
@@ -151,6 +152,9 @@ int main(int argc, char **argv)
     struct sockaddr_in addr;
     unsigned int addr_len = sizeof(addr);
 
+    /* ignore SIGPIPE so that server can continue running when client pipe closes abruptly */
+    signal(SIGPIPE, SIG_IGN);
+
     /* Splash */
     printf("\nsslecho : Simple Echo Client/Server (OpenSSL 3.0.1-dev) : %s : %s\n\n", __DATE__,
     __TIME__);
@@ -218,6 +222,8 @@ int main(int argc, char **argv)
                     if ((rxlen = SSL_read(ssl, rxbuf, rxcap)) <= 0) {
                         if (rxlen == 0) {
                             printf("Client closed connection\n");
+                        } else {
+                            printf("SSL_read returned %d\n", rxlen);
                         }
                         ERR_print_errors_fp(stderr);
                         break;