Module Name:    src
Committed By:   martin
Date:           Mon Jun 14 11:28:28 UTC 2021

Modified Files:
        src/usr.bin/ftp [netbsd-9]: ftp.c util.c

Log Message:
Pull up following revision(s) (requested by lukem in ticket #1291):

        usr.bin/ftp/ftp.c: revision 1.169
        usr.bin/ftp/util.c: revision 1.161

ftp: exit if lostpeer invoked by a signal

lostpeer() calls too many async-unsafe functions (both directly
and indirectly) to close and cleanup the remote connections,
so just exit after the cleanup if invoked by a signal.

Reported in private mail by Qi Hou.

May also resolve a crash reported by Thomas Klausner.


To generate a diff of this commit:
cvs rdiff -u -r1.168.2.2 -r1.168.2.3 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.160 -r1.160.2.1 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.168.2.2 src/usr.bin/ftp/ftp.c:1.168.2.3
--- src/usr.bin/ftp/ftp.c:1.168.2.2	Mon Jun 14 11:22:16 2021
+++ src/usr.bin/ftp/ftp.c	Mon Jun 14 11:28:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.168.2.2 2021/06/14 11:22:16 martin Exp $	*/
+/*	$NetBSD: ftp.c,v 1.168.2.3 2021/06/14 11:28:28 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.168.2.2 2021/06/14 11:22:16 martin Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.168.2.3 2021/06/14 11:28:28 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -2074,7 +2074,7 @@ gunique(const char *local)
  *	needs to get back to a known state.
  */
 static void
-abort_squared(int dummy)
+abort_squared(int signo)
 {
 	char msgbuf[100];
 	size_t len;
@@ -2084,7 +2084,7 @@ abort_squared(int dummy)
 	len = strlcpy(msgbuf, "\nremote abort aborted; closing connection.\n",
 	    sizeof(msgbuf));
 	write(fileno(ttyout), msgbuf, len);
-	lostpeer(0);
+	lostpeer(signo);
 	siglongjmp(xferabort, 1);
 }
 

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.160 src/usr.bin/ftp/util.c:1.160.2.1
--- src/usr.bin/ftp/util.c:1.160	Sat Jun 22 23:40:53 2019
+++ src/usr.bin/ftp/util.c	Mon Jun 14 11:28:28 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $	*/
+/*	$NetBSD: util.c,v 1.160.2.1 2021/06/14 11:28:28 martin Exp $	*/
 
 /*-
- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -64,7 +64,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $");
+__RCSID("$NetBSD: util.c,v 1.160.2.1 2021/06/14 11:28:28 martin Exp $");
 #endif /* not lint */
 
 /*
@@ -324,9 +324,10 @@ intr(int signo)
 /*
  * Signal handler for lost connections; cleanup various elements of
  * the connection state, and call cleanuppeer() to finish it off.
+ * This function is not signal safe, so exit if called by a signal.
  */
 void
-lostpeer(int dummy)
+lostpeer(int signo)
 {
 	int oerrno = errno;
 
@@ -356,6 +357,9 @@ lostpeer(int dummy)
 	proxflag = 0;
 	pswitch(0);
 	cleanuppeer();
+	if (signo) {
+		errx(1, "lostpeer due to signal %d", signo);
+	}
 	errno = oerrno;
 }
 

Reply via email to