From a71ebfeedec719d01fcebce5f8b11f30f655eec7 Mon Sep 17 00:00:00 2001 From: deraadt Date: Wed, 11 Mar 2026 14:59:10 +0000 Subject: [PATCH] pass "e" to fopen() to set O_CLOEXEC ok guenther --- lib/libutil/login_fbtab.c | 4 ++-- lib/libutil/passwd.c | 6 +++--- lib/libutil/pidfile.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/libutil/login_fbtab.c b/lib/libutil/login_fbtab.c index f19431d3956..3c7c43a839a 100644 --- a/lib/libutil/login_fbtab.c +++ b/lib/libutil/login_fbtab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login_fbtab.c,v 1.21 2025/11/24 12:44:25 jca Exp $ */ +/* $OpenBSD: login_fbtab.c,v 1.22 2026/03/11 14:59:10 deraadt Exp $ */ /************************************************************************ * Copyright 1995 by Wietse Venema. All rights reserved. Some individual @@ -87,7 +87,7 @@ login_fbtab(const char *tty, uid_t uid, gid_t gid) mode_t prot; ssize_t len; - if ((fp = fopen(_PATH_FBTAB, "r")) == NULL) + if ((fp = fopen(_PATH_FBTAB, "re")) == NULL) return; while ((len = getline(&buf, &bufsize, fp)) != -1) { diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c index 7acd7085d42..4d0cffa1187 100644 --- a/lib/libutil/passwd.c +++ b/lib/libutil/passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: passwd.c,v 1.56 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: passwd.c,v 1.57 2026/03/11 14:59:10 deraadt Exp $ */ /* * Copyright (c) 1987, 1993, 1994, 1995 @@ -324,9 +324,9 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, const struct passwd *opw) if (!master) pw_error(NULL, 0, 1); - if (!(from = fdopen(ffd, "r"))) + if (!(from = fdopen(ffd, "re"))) pw_error(master, 1, 1); - if (!(to = fdopen(tfd, "w"))) + if (!(to = fdopen(tfd, "we"))) pw_error(pw_lck ? pw_lck : NULL, pw_lck ? 1 : 0, 1); for (done = 0; fgets(buf, (int)sizeof(buf), from);) { diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index e2d301868f8..84ddca7f51e 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pidfile.c,v 1.14 2019/06/28 14:20:40 schwarze Exp $ */ +/* $OpenBSD: pidfile.c,v 1.15 2026/03/11 14:59:10 deraadt Exp $ */ /* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */ /*- @@ -62,7 +62,7 @@ pidfile(const char *basename) if (asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename) == -1) return (-1); - if ((f = fopen(pidfile_path, "w")) == NULL) { + if ((f = fopen(pidfile_path, "we")) == NULL) { save_errno = errno; free(pidfile_path); pidfile_path = NULL;