diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-09-25 19:13:57 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-09-25 19:13:57 +0000 |
commit | c86e1ca236d2b91ddd4f535810e0946d03a4a636 (patch) | |
tree | 57247d96b49479390d2736a1ed866a22e9ed4807 /usr.bin/calendar | |
parent | 0773c93b484477f45af79449186a25b432358bbe (diff) |
Calling waitpid(pid,...) where pid is either uninitialized or
-1 because vflork() failed is bad. Initialize pid to -1 and call
waitpid() only when pid != -1.
Uninitialized use of pid found by clang.
Suggestion of -1 from millert@.
ok millert@
Diffstat (limited to 'usr.bin/calendar')
-rw-r--r-- | usr.bin/calendar/io.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index 8abe7996917..7d4353e87f5 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.46 2017/08/21 21:41:13 deraadt Exp $ */ +/* $OpenBSD: io.c,v 1.47 2017/09/25 19:13:56 krw Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -385,7 +385,7 @@ closecal(FILE *fp) struct stat sbuf; int nread, pdes[2], status; char buf[1024]; - pid_t pid; + pid_t pid = -1; if (!doall) return; @@ -422,9 +422,11 @@ closecal(FILE *fp) (void)write(pdes[1], buf, nread); (void)close(pdes[1]); done: (void)fclose(fp); - while (waitpid(pid, &status, 0) == -1) { - if (errno != EINTR) - break; + if (pid != -1) { + while (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) + break; + } } } |