From: Thomas Pornin Date: Sun, 20 Nov 2016 15:23:00 +0000 (+0100) Subject: SIGPIPE shall be ignored in most network-related cases. X-Git-Tag: v0.4~50 X-Git-Url: https://bearssl.org/gitweb//home/git/?a=commitdiff_plain;h=3b044d4296b1dffa5586658e152e1c7bd8144410;p=BearSSL SIGPIPE shall be ignored in most network-related cases. --- diff --git a/samples/client_basic.c b/samples/client_basic.c index d4f79fb..1609f43 100644 --- a/samples/client_basic.c +++ b/samples/client_basic.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -260,6 +261,11 @@ main(int argc, char *argv[]) path = "/"; } + /* + * Ignore SIGPIPE to avoid crashing in case of abrupt socket close. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the socket to the target server. */ diff --git a/samples/server_basic.c b/samples/server_basic.c index fdd801e..92c7d42 100644 --- a/samples/server_basic.c +++ b/samples/server_basic.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -278,6 +279,11 @@ main(int argc, char *argv[]) } port = argv[1]; + /* + * Ignore SIGPIPE to avoid crashing in case of abrupt socket close. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the server socket. */ diff --git a/tools/client.c b/tools/client.c index 2c2985f..552b7f9 100644 --- a/tools/client.c +++ b/tools/client.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -619,6 +620,11 @@ do_client(int argc, char *argv[]) br_ssl_engine_set_buffer(&cc.eng, iobuf, iobuf_len, bidi); br_ssl_client_reset(&cc, sni, 0); + /* + * We need to avoid SIGPIPE. + */ + signal(SIGPIPE, SIG_IGN); + /* * Connect to the peer. */ diff --git a/tools/server.c b/tools/server.c index 71cfa5d..c6978cf 100644 --- a/tools/server.c +++ b/tools/server.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1010,6 +1011,11 @@ do_server(int argc, char *argv[]) br_ssl_engine_set_buffer(&cc.eng, iobuf, iobuf_len, bidi); + /* + * We need to ignore SIGPIPE. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the server socket. */