summaryrefslogtreecommitdiff
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2020-07-04 11:23:36 +0000
committerkn <kn@cvs.openbsd.org>2020-07-04 11:23:36 +0000
commit12394eb3d13e77787a358468b6a19f9b836e1b14 (patch)
treeb9e6925825700ce4bd0ffaade18387a037dee361 /usr.bin/ftp
parent875d81686362f6e82e41cb667b3071be18349d99 (diff)
Avoid malloc(3) calls in signal handler
Fetch aborts through SIGINT (^C) print a message with fputs(3), but this calls malloc() on its own, which is not supported from interrupt handler context. Fix it by using write(2) which avoids further memory allocations. While here, merge abortfile() into the identical aborthttp() with a more generic "fetch aborted." message for simplicity. Spotted with vm.malloc_conf=SU and ^C on a port's "make fetch" causing ftp(49660) in malloc(): recursive call Abort trap (core dumped) OK jca (who came up with using write(2) independently)
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/fetch.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 5bc9881d25b..e9da609043d 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.196 2020/07/04 10:18:49 jca Exp $ */
+/* $OpenBSD: fetch.c,v 1.197 2020/07/04 11:23:35 kn Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -72,7 +72,6 @@ static int file_get(const char *, const char *);
static int url_get(const char *, const char *, const char *, int);
static int save_chunked(FILE *, struct tls *, int , char *, size_t);
static void aborthttp(int);
-static void abortfile(int);
static char hextochar(const char *);
static char *urldecode(const char *);
static char *recode_credentials(const char *_userinfo);
@@ -248,7 +247,7 @@ file_get(const char *path, const char *outfile)
(void)signal(SIGINFO, oldinti);
goto cleanup_copy;
}
- oldintr = signal(SIGINT, abortfile);
+ oldintr = signal(SIGINT, aborthttp);
bytes = 0;
hashbytes = mark;
@@ -1187,24 +1186,10 @@ save_chunked(FILE *fin, struct tls *tls, int out, char *buf, size_t buflen)
static void
aborthttp(int signo)
{
+ const char errmsg[] = "\nfetch aborted.\n";
alarmtimer(0);
- fputs("\nhttp fetch aborted.\n", ttyout);
- (void)fflush(ttyout);
- longjmp(httpabort, 1);
-}
-
-/*
- * Abort a http retrieval
- */
-/* ARGSUSED */
-static void
-abortfile(int signo)
-{
-
- alarmtimer(0);
- fputs("\nfile fetch aborted.\n", ttyout);
- (void)fflush(ttyout);
+ write(fileno(ttyout), errmsg, sizeof(errmsg) - 1);
longjmp(httpabort, 1);
}