View | Details | Raw Unified | Return to bug 170369
Collapse All | Expand All

(-)lib/libc/gen/arc4random.c (-1 / +1 lines)
Lines 114-120 Link Here
114
		u_int8_t 	rnd[KEYSIZE];
114
		u_int8_t 	rnd[KEYSIZE];
115
	} rdat;
115
	} rdat;
116
116
117
	fd = _open(RANDOMDEV, O_RDONLY, 0);
117
	fd = _open(RANDOMDEV, O_RDONLY | O_CLOEXEC, 0);
118
	done = 0;
118
	done = 0;
119
	if (fd >= 0) {
119
	if (fd >= 0) {
120
		if (_read(fd, &rdat, KEYSIZE) == KEYSIZE)
120
		if (_read(fd, &rdat, KEYSIZE) == KEYSIZE)
(-)lib/libc/gen/fmtmsg.c (-1 / +1 lines)
Lines 87-93 Link Here
87
		if (output == NULL)
87
		if (output == NULL)
88
			return (MM_NOCON);
88
			return (MM_NOCON);
89
		if (*output != '\0') {
89
		if (*output != '\0') {
90
			if ((fp = fopen("/dev/console", "a")) == NULL) {
90
			if ((fp = fopen("/dev/console", "ae")) == NULL) {
91
				free(output);
91
				free(output);
92
				return (MM_NOCON);
92
				return (MM_NOCON);
93
			}
93
			}
(-)lib/libc/gen/fts-compat.c (-5 / +7 lines)
Lines 218-224 Link Here
218
	 * and ".." are all fairly nasty problems.  Note, if we can't get the
218
	 * and ".." are all fairly nasty problems.  Note, if we can't get the
219
	 * descriptor we run anyway, just more slowly.
219
	 * descriptor we run anyway, just more slowly.
220
	 */
220
	 */
221
	if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
221
	if (!ISSET(FTS_NOCHDIR) &&
222
	    (sp->fts_rfd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
222
		SET(FTS_NOCHDIR);
223
		SET(FTS_NOCHDIR);
223
224
224
	return (sp);
225
	return (sp);
Lines 347-353 Link Here
347
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
348
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
348
		p->fts_info = fts_stat(sp, p, 1);
349
		p->fts_info = fts_stat(sp, p, 1);
349
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
350
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
350
			if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
351
			if ((p->fts_symfd = _open(".",
352
						  O_RDONLY | O_CLOEXEC, 0)) < 0) {
351
				p->fts_errno = errno;
353
				p->fts_errno = errno;
352
				p->fts_info = FTS_ERR;
354
				p->fts_info = FTS_ERR;
353
			} else
355
			} else
Lines 438-444 Link Here
438
			p->fts_info = fts_stat(sp, p, 1);
440
			p->fts_info = fts_stat(sp, p, 1);
439
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
441
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
440
				if ((p->fts_symfd =
442
				if ((p->fts_symfd =
441
				    _open(".", O_RDONLY, 0)) < 0) {
443
				    _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) {
442
					p->fts_errno = errno;
444
					p->fts_errno = errno;
443
					p->fts_info = FTS_ERR;
445
					p->fts_info = FTS_ERR;
444
				} else
446
				} else
Lines 579-585 Link Here
579
	    ISSET(FTS_NOCHDIR))
581
	    ISSET(FTS_NOCHDIR))
580
		return (sp->fts_child = fts_build(sp, instr));
582
		return (sp->fts_child = fts_build(sp, instr));
581
583
582
	if ((fd = _open(".", O_RDONLY, 0)) < 0)
584
	if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
583
		return (NULL);
585
		return (NULL);
584
	sp->fts_child = fts_build(sp, instr);
586
	sp->fts_child = fts_build(sp, instr);
585
	if (fchdir(fd))
587
	if (fchdir(fd))
Lines 1178-1184 Link Here
1178
	newfd = fd;
1180
	newfd = fd;
1179
	if (ISSET(FTS_NOCHDIR))
1181
	if (ISSET(FTS_NOCHDIR))
1180
		return (0);
1182
		return (0);
1181
	if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
1183
	if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0)
1182
		return (-1);
1184
		return (-1);
1183
	if (_fstat(newfd, &sb)) {
1185
	if (_fstat(newfd, &sb)) {
1184
		ret = -1;
1186
		ret = -1;
(-)lib/libc/gen/fts.c (-5 / +7 lines)
Lines 213-219 Link Here
213
	 * and ".." are all fairly nasty problems.  Note, if we can't get the
213
	 * and ".." are all fairly nasty problems.  Note, if we can't get the
214
	 * descriptor we run anyway, just more slowly.
214
	 * descriptor we run anyway, just more slowly.
215
	 */
215
	 */
216
	if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
216
	if (!ISSET(FTS_NOCHDIR) && 
217
	    (sp->fts_rfd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
217
		SET(FTS_NOCHDIR);
218
		SET(FTS_NOCHDIR);
218
219
219
	return (sp);
220
	return (sp);
Lines 342-348 Link Here
342
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
343
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
343
		p->fts_info = fts_stat(sp, p, 1);
344
		p->fts_info = fts_stat(sp, p, 1);
344
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
345
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
345
			if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
346
			if ((p->fts_symfd = _open(".",
347
						  O_RDONLY | O_CLOEXEC, 0)) < 0) {
346
				p->fts_errno = errno;
348
				p->fts_errno = errno;
347
				p->fts_info = FTS_ERR;
349
				p->fts_info = FTS_ERR;
348
			} else
350
			} else
Lines 433-439 Link Here
433
			p->fts_info = fts_stat(sp, p, 1);
435
			p->fts_info = fts_stat(sp, p, 1);
434
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
436
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
435
				if ((p->fts_symfd =
437
				if ((p->fts_symfd =
436
				    _open(".", O_RDONLY, 0)) < 0) {
438
				    _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) {
437
					p->fts_errno = errno;
439
					p->fts_errno = errno;
438
					p->fts_info = FTS_ERR;
440
					p->fts_info = FTS_ERR;
439
				} else
441
				} else
Lines 574-580 Link Here
574
	    ISSET(FTS_NOCHDIR))
576
	    ISSET(FTS_NOCHDIR))
575
		return (sp->fts_child = fts_build(sp, instr));
577
		return (sp->fts_child = fts_build(sp, instr));
576
578
577
	if ((fd = _open(".", O_RDONLY, 0)) < 0)
579
	if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
578
		return (NULL);
580
		return (NULL);
579
	sp->fts_child = fts_build(sp, instr);
581
	sp->fts_child = fts_build(sp, instr);
580
	if (fchdir(fd)) {
582
	if (fchdir(fd)) {
Lines 1145-1151 Link Here
1145
	newfd = fd;
1147
	newfd = fd;
1146
	if (ISSET(FTS_NOCHDIR))
1148
	if (ISSET(FTS_NOCHDIR))
1147
		return (0);
1149
		return (0);
1148
	if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
1150
	if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0)
1149
		return (-1);
1151
		return (-1);
1150
	if (_fstat(newfd, &sb)) {
1152
	if (_fstat(newfd, &sb)) {
1151
		ret = -1;
1153
		ret = -1;
(-)lib/libc/gen/getcap.c (-2 / +4 lines)
Lines 241-247 Link Here
241
			myfd = 0;
241
			myfd = 0;
242
		} else {
242
		} else {
243
			(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
243
			(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
244
			if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
244
			if ((capdbp = dbopen(pbuf,
245
					     O_RDONLY | O_CLOEXEC, 
246
					     0, DB_HASH, 0))
245
			     != NULL) {
247
			     != NULL) {
246
				free(record);
248
				free(record);
247
				retval = cdbget(capdbp, &record, name);
249
				retval = cdbget(capdbp, &record, name);
Lines 264-270 Link Here
264
				*cap = cbuf;
266
				*cap = cbuf;
265
				return (retval);
267
				return (retval);
266
			} else {
268
			} else {
267
				fd = _open(*db_p, O_RDONLY, 0);
269
				fd = _open(*db_p, O_RDONLY | O_CLOEXEC, 0);
268
				if (fd < 0)
270
				if (fd < 0)
269
					continue;
271
					continue;
270
				myfd = 1;
272
				myfd = 1;
(-)lib/libc/gen/getcwd.c (-1 / +1 lines)
Lines 140-146 Link Here
140
140
141
		/* Open and stat parent directory. */
141
		/* Open and stat parent directory. */
142
		fd = _openat(dir != NULL ? dirfd(dir) : AT_FDCWD,
142
		fd = _openat(dir != NULL ? dirfd(dir) : AT_FDCWD,
143
				"..", O_RDONLY);
143
				"..", O_RDONLY | O_CLOEXEC);
144
		if (fd == -1)
144
		if (fd == -1)
145
			goto err;
145
			goto err;
146
		if (dir)
146
		if (dir)
(-)lib/libc/gen/getgrent.c (-4 / +4 lines)
Lines 810-816 Link Here
810
		if (st->fp != NULL)
810
		if (st->fp != NULL)
811
			rewind(st->fp);
811
			rewind(st->fp);
812
		else if (stayopen)
812
		else if (stayopen)
813
			st->fp = fopen(_PATH_GROUP, "r");
813
			st->fp = fopen(_PATH_GROUP, "re");
814
		break;
814
		break;
815
	case ENDGRENT:
815
	case ENDGRENT:
816
		if (st->fp != NULL) {
816
		if (st->fp != NULL) {
Lines 861-867 Link Here
861
	if (*errnop != 0)
861
	if (*errnop != 0)
862
		return (NS_UNAVAIL);
862
		return (NS_UNAVAIL);
863
	if (st->fp == NULL &&
863
	if (st->fp == NULL &&
864
	    ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) {
864
	    ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) {
865
		*errnop = errno;
865
		*errnop = errno;
866
		return (NS_UNAVAIL);
866
		return (NS_UNAVAIL);
867
	}
867
	}
Lines 1251-1257 Link Here
1251
		if (st->fp != NULL)
1251
		if (st->fp != NULL)
1252
			rewind(st->fp);
1252
			rewind(st->fp);
1253
		else if (stayopen)
1253
		else if (stayopen)
1254
			st->fp = fopen(_PATH_GROUP, "r");
1254
			st->fp = fopen(_PATH_GROUP, "re");
1255
		set_setent(dtab, mdata);
1255
		set_setent(dtab, mdata);
1256
		(void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent",
1256
		(void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent",
1257
		    compatsrc, 0);
1257
		    compatsrc, 0);
Lines 1335-1341 Link Here
1335
	if (*errnop != 0)
1335
	if (*errnop != 0)
1336
		return (NS_UNAVAIL);
1336
		return (NS_UNAVAIL);
1337
	if (st->fp == NULL &&
1337
	if (st->fp == NULL &&
1338
	    ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) {
1338
	    ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) {
1339
		*errnop = errno;
1339
		*errnop = errno;
1340
		rv = NS_UNAVAIL;
1340
		rv = NS_UNAVAIL;
1341
		goto fin;
1341
		goto fin;
(-)lib/libc/gen/getnetgrent.c (-2 / +2 lines)
Lines 173-179 Link Here
173
		if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) &&
173
		if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) &&
174
		    errno == ENOENT) || _yp_statp.st_size == 0)
174
		    errno == ENOENT) || _yp_statp.st_size == 0)
175
			_use_only_yp = _netgr_yp_enabled = 1;
175
			_use_only_yp = _netgr_yp_enabled = 1;
176
		if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){
176
		if ((netf = fopen(_PATH_NETGROUP,"re")) != NULL ||_use_only_yp){
177
		/*
177
		/*
178
		 * Icky: grab the first character of the netgroup file
178
		 * Icky: grab the first character of the netgroup file
179
		 * and turn on NIS if it's a '+'. rewind the stream
179
		 * and turn on NIS if it's a '+'. rewind the stream
Lines 197-203 Link Here
197
				return;
197
				return;
198
			}
198
			}
199
#else
199
#else
200
		if ((netf = fopen(_PATH_NETGROUP, "r"))) {
200
		if ((netf = fopen(_PATH_NETGROUP, "re"))) {
201
#endif
201
#endif
202
			if (parse_netgrp(group))
202
			if (parse_netgrp(group))
203
				endnetgrent();
203
				endnetgrent();
(-)lib/libc/gen/nlist.c (-1 / +1 lines)
Lines 66-72 Link Here
66
{
66
{
67
	int fd, n;
67
	int fd, n;
68
68
69
	fd = _open(name, O_RDONLY, 0);
69
	fd = _open(name, O_RDONLY | O_CLOEXEC, 0);
70
	if (fd < 0)
70
	if (fd < 0)
71
		return (-1);
71
		return (-1);
72
	n = __fdnlist(fd, list);
72
	n = __fdnlist(fd, list);
(-)lib/libc/gen/pututxline.c (-3 / +3 lines)
Lines 47-53 Link Here
47
	struct stat sb;
47
	struct stat sb;
48
	int fd;
48
	int fd;
49
49
50
	fd = _open(file, O_CREAT|O_RDWR|O_EXLOCK, 0644);
50
	fd = _open(file, O_CREAT|O_RDWR|O_EXLOCK|O_CLOEXEC, 0644);
51
	if (fd < 0)
51
	if (fd < 0)
52
		return (NULL);
52
		return (NULL);
53
53
Lines 219-225 Link Here
219
	struct stat sb;
219
	struct stat sb;
220
	int fd;
220
	int fd;
221
221
222
	fd = _open(_PATH_UTX_LASTLOGIN, O_RDWR, 0644);
222
	fd = _open(_PATH_UTX_LASTLOGIN, O_RDWR | O_CLOEXEC, 0644);
223
	if (fd < 0)
223
	if (fd < 0)
224
		return;
224
		return;
225
225
Lines 253-259 Link Here
253
	vec[1].iov_len = l;
253
	vec[1].iov_len = l;
254
	l = htobe16(l);
254
	l = htobe16(l);
255
255
256
	fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND, 0644);
256
	fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND|O_CLOEXEC, 0644);
257
	if (fd < 0)
257
	if (fd < 0)
258
		return (-1);
258
		return (-1);
259
	if (_writev(fd, vec, 2) == -1)
259
	if (_writev(fd, vec, 2) == -1)
(-)lib/libc/gen/readpassphrase.c (-1 / +1 lines)
Lines 68-74 Link Here
68
	 * stdin and write to stderr unless a tty is required.
68
	 * stdin and write to stderr unless a tty is required.
69
	 */
69
	 */
70
	if ((flags & RPP_STDIN) ||
70
	if ((flags & RPP_STDIN) ||
71
	    (input = output = _open(_PATH_TTY, O_RDWR)) == -1) {
71
	    (input = output = _open(_PATH_TTY, O_RDWR | O_CLOEXEC)) == -1) {
72
		if (flags & RPP_REQUIRE_TTY) {
72
		if (flags & RPP_REQUIRE_TTY) {
73
			errno = ENOTTY;
73
			errno = ENOTTY;
74
			return(NULL);
74
			return(NULL);
(-)lib/libc/gen/sem_new.c (-1 / +1 lines)
Lines 198-204 Link Here
198
		goto error;
198
		goto error;
199
	}
199
	}
200
200
201
	fd = _open(path, flags|O_RDWR, mode);
201
	fd = _open(path, flags|O_RDWR|O_CLOEXEC, mode);
202
	if (fd == -1)
202
	if (fd == -1)
203
		goto error;
203
		goto error;
204
	if (flock(fd, LOCK_EX) == -1)
204
	if (flock(fd, LOCK_EX) == -1)
(-)lib/libc/gen/syslog.c (-1 / +2 lines)
Lines 300-306 Link Here
300
	 * Make sure the error reported is the one from the syslogd failure.
300
	 * Make sure the error reported is the one from the syslogd failure.
301
	 */
301
	 */
302
	if (LogStat & LOG_CONS &&
302
	if (LogStat & LOG_CONS &&
303
	    (fd = _open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) {
303
	    (fd = _open(_PATH_CONSOLE,
304
			O_WRONLY|O_NONBLOCK|O_CLOEXEC, 0)) >= 0) {
304
		struct iovec iov[2];
305
		struct iovec iov[2];
305
		struct iovec *v = iov;
306
		struct iovec *v = iov;

Return to bug 170369