Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Check fcntl return values out of paranoia.
details: https://anonhg.NetBSD.org/src/rev/a052ef4294d6
branches: trunk
changeset: 352983:a052ef4294d6
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Apr 16 20:57:14 2017 +0000
description:
Check fcntl return values out of paranoia.
CID 975277
CID 975278
diffstat:
usr.bin/make/job.c | 47 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 34 insertions(+), 13 deletions(-)
diffs (107 lines):
diff -r e5dfe4cf81dc -r a052ef4294d6 usr.bin/make/job.c
--- a/usr.bin/make/job.c Sun Apr 16 20:49:09 2017 +0000
+++ b/usr.bin/make/job.c Sun Apr 16 20:57:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $ */
+/* $NetBSD: job.c,v 1.189 2017/04/16 20:57:14 riastradh Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.189 2017/04/16 20:57:14 riastradh Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $");
+__RCSID("$NetBSD: job.c,v 1.189 2017/04/16 20:57:14 riastradh Exp $");
#endif
#endif /* not lint */
#endif
@@ -411,7 +411,7 @@
static void
JobCreatePipe(Job *job, int minfd)
{
- int i, fd;
+ int i, fd, flags;
if (pipe(job->jobPipe) == -1)
Punt("Cannot create pipe: %s", strerror(errno));
@@ -426,8 +426,10 @@
}
/* Set close-on-exec flag for both */
- (void)fcntl(job->jobPipe[0], F_SETFD, FD_CLOEXEC);
- (void)fcntl(job->jobPipe[1], F_SETFD, FD_CLOEXEC);
+ if (fcntl(job->jobPipe[0], F_SETFD, FD_CLOEXEC) == -1)
+ Punt("Cannot set close-on-exec: %s", strerror(errno));
+ if (fcntl(job->jobPipe[1], F_SETFD, FD_CLOEXEC) == -1)
+ Punt("Cannot set close-on-exec: %s", strerror(errno));
/*
* We mark the input side of the pipe non-blocking; we poll(2) the
@@ -435,8 +437,12 @@
* race for the token when a new one becomes available, so the read
* from the pipe should not block.
*/
- fcntl(job->jobPipe[0], F_SETFL,
- fcntl(job->jobPipe[0], F_GETFL, 0) | O_NONBLOCK);
+ flags = fcntl(job->jobPipe[0], F_GETFL, 0);
+ if (flags == -1)
+ Punt("Cannot get flags: %s", strerror(errno));
+ flags |= O_NONBLOCK;
+ if (fcntl(job->jobPipe[0], F_SETFL, flags) == -1)
+ Punt("Cannot set flags: %s", strerror(errno));
}
/*-
@@ -1365,15 +1371,27 @@
execError("dup2", "job->cmdFILE");
_exit(1);
}
- (void)fcntl(0, F_SETFD, 0);
- (void)lseek(0, (off_t)0, SEEK_SET);
+ if (fcntl(0, F_SETFD, 0) == -1) {
+ execError("fcntl clear close-on-exec", "stdin");
+ _exit(1);
+ }
+ if (lseek(0, (off_t)0, SEEK_SET) == -1) {
+ execError("lseek to 0", "stdin");
+ _exit(1);
+ }
if (job->node->type & (OP_MAKE | OP_SUBMAKE)) {
/*
* Pass job token pipe to submakes.
*/
- fcntl(tokenWaitJob.inPipe, F_SETFD, 0);
- fcntl(tokenWaitJob.outPipe, F_SETFD, 0);
+ if (fcntl(tokenWaitJob.inPipe, F_SETFD, 0) == -1) {
+ execError("clear close-on-exec", "tokenWaitJob.inPipe");
+ _exit(1);
+ }
+ if (fcntl(tokenWaitJob.outPipe, F_SETFD, 0) == -1) {
+ execError("clear close-on-exec", "tokenWaitJob.outPipe");
+ _exit(1);
+ }
}
/*
@@ -1390,7 +1408,10 @@
* it before routing the shell's error output to the same place as
* its standard output.
*/
- (void)fcntl(1, F_SETFD, 0);
+ if (fcntl(1, F_SETFD, 0) == -1) {
+ execError("clear close-on-exec", "stdout");
+ _exit(1);
+ }
if (dup2(1, 2) == -1) {
execError("dup2", "1, 2");
_exit(1);
Home |
Main Index |
Thread Index |
Old Index