summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2020-07-04 11:23:35 +0000
committerkn <kn@openbsd.org>2020-07-04 11:23:35 +0000
commit5fbde59f90414c47d0e7b11b9ca8ab51e4d33f38 (patch)
treeb0183218db5d788dd727d0ca06945d2c2b6c939e
parentFix intermittent failing device initialization seen on some Synaptics (diff)
downloadwireguard-openbsd-5fbde59f90414c47d0e7b11b9ca8ab51e4d33f38.tar.xz
wireguard-openbsd-5fbde59f90414c47d0e7b11b9ca8ab51e4d33f38.zip
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)
-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);
}