From: Lars Ingebrigtsen Date: Tue, 1 Nov 2016 19:57:28 +0000 (+0100) Subject: Don't segfault on timed-out TLS connections X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1^2~5^2~21^2~2416 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=126c879df42f741fe486236aea538290a8c2ed64;p=emacs.git Don't segfault on timed-out TLS connections * src/process.c (finish_after_tls_connection): Check that the file descriptor is still alive before proceeding (bug#24811). Also clean up the code slightly. --- diff --git a/src/process.c b/src/process.c index 8cf045ca9c2..d27b57d560f 100644 --- a/src/process.c +++ b/src/process.c @@ -3094,19 +3094,24 @@ finish_after_tls_connection (Lisp_Object proc) build_string ("The Network Security Manager stopped the connections"))); deactivate_process (proc); } - else + else if (p->outfd < 0) { - /* If we cleared the connection wait mask before we did - the TLS setup, then we have to say that the process - is finally "open" here. */ - if (! FD_ISSET (p->outfd, &connect_wait_mask)) - { - pset_status (p, Qrun); - /* Execute the sentinel here. If we had relied on - status_notify to do it later, it will read input - from the process before calling the sentinel. */ - exec_sentinel (proc, build_string ("open\n")); - } + /* The counterparty may have closed the connection (especially + if the NSM promt above take a long time), so recheck the file + descriptor here. */ + pset_status (p, Qfailed); + deactivate_process (proc); + } + else if (! FD_ISSET (p->outfd, &connect_wait_mask)) + { + /* If we cleared the connection wait mask before we did the TLS + setup, then we have to say that the process is finally "open" + here. */ + pset_status (p, Qrun); + /* Execute the sentinel here. If we had relied on status_notify + to do it later, it will read input from the process before + calling the sentinel. */ + exec_sentinel (proc, build_string ("open\n")); } } #endif