From d1fee0dd15596800b1a36b0a62aef1ed8fb2f5fe Mon Sep 17 00:00:00 2001 From: itojun Date: Wed, 21 Nov 2001 06:52:35 +0000 Subject: [PATCH] deal with wait3() returning -1. be careful on malloc failures. sync with kame --- usr.sbin/faithd/faithd.c | 13 +++++++++---- usr.sbin/faithd/prefix.c | 6 ++++-- usr.sbin/faithd/tcp.c | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/usr.sbin/faithd/faithd.c b/usr.sbin/faithd/faithd.c index 119204e3cd3e..74d2aab67f1b 100644 --- a/usr.sbin/faithd/faithd.c +++ b/usr.sbin/faithd/faithd.c @@ -1,4 +1,4 @@ -/* $NetBSD: faithd.c,v 1.20 2001/09/05 01:22:24 itojun Exp $ */ +/* $NetBSD: faithd.c,v 1.21 2001/11/21 06:52:35 itojun Exp $ */ /* $KAME: faithd.c,v 1.40 2001/07/02 14:36:48 itojun Exp $ */ /* @@ -301,9 +301,13 @@ daemon_main(int argc, char **argv) exit_stderr("too many arguments"); serverpath = malloc(strlen(argv[NUMPRG]) + 1); + if (!serverpath) + exit_stderr("not enough core"); strcpy(serverpath, argv[NUMPRG]); for (i = 0; i < serverargc; i++) { serverarg[i] = malloc(strlen(argv[i + NUMARG]) + 1); + if (!serverarg[i]) + exit_stderr("not enough core"); strcpy(serverarg[i], argv[i + NUMARG]); } serverarg[i] = NULL; @@ -770,9 +774,10 @@ sig_child(int sig) int status; pid_t pid; - pid = wait3(&status, WNOHANG, (struct rusage *)0); - if (pid && WEXITSTATUS(status)) - syslog(LOG_WARNING, "child %d exit status 0x%x", pid, status); + while ((pid = wait3(&status, WNOHANG, (struct rusage *)0)) > 0) + if (WEXITSTATUS(status)) + syslog(LOG_WARNING, "child %d exit status 0x%x", + pid, status); } void diff --git a/usr.sbin/faithd/prefix.c b/usr.sbin/faithd/prefix.c index aaf7166224a4..e89b43849e4a 100644 --- a/usr.sbin/faithd/prefix.c +++ b/usr.sbin/faithd/prefix.c @@ -1,4 +1,4 @@ -/* $NetBSD: prefix.c,v 1.2 2001/09/05 01:22:24 itojun Exp $ */ +/* $NetBSD: prefix.c,v 1.3 2001/11/21 06:52:35 itojun Exp $ */ /* $KAME: prefix.c,v 1.9 2001/07/02 14:36:49 itojun Exp $ */ /* @@ -67,12 +67,14 @@ prefix_set(s, prefix, slash) struct prefix *prefix; int slash; { - char *p, *q, *r; + char *p = NULL, *q, *r; struct addrinfo hints, *res = NULL; int max; char *a; p = strdup(s); + if (!p) + goto fail; q = strchr(p, '/'); if (q) { if (!slash) diff --git a/usr.sbin/faithd/tcp.c b/usr.sbin/faithd/tcp.c index d6788609855a..d485c484afad 100644 --- a/usr.sbin/faithd/tcp.c +++ b/usr.sbin/faithd/tcp.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcp.c,v 1.5 2001/09/05 01:22:24 itojun Exp $ */ +/* $NetBSD: tcp.c,v 1.6 2001/11/21 06:52:35 itojun Exp $ */ /* $KAME: tcp.c,v 1.6 2001/07/02 14:36:49 itojun Exp $ */ /* @@ -92,7 +92,7 @@ sig_child(int sig) pid_t pid; pid = wait3(&status, WNOHANG, (struct rusage *)0); - if (pid && WEXITSTATUS(status)) + if (pid > 0 && WEXITSTATUS(status)) syslog(LOG_WARNING, "child %d exit status 0x%x", pid, status); exit_success("terminate connection due to child termination"); }