From 7447aa4eb01d42459bc5852f17a164f5b2f486f7 Mon Sep 17 00:00:00 2001 From: deraadt Date: Wed, 20 Jul 2016 19:25:39 +0000 Subject: [PATCH] As a general rule, fchown before fchmod is a safer order (because many systems throw away bits upon chown). Not in this case, but code gets copied.. ok krw --- sbin/dhclient/dhclient.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 7f89b1d5777..6e27d0e35e2 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.374 2016/07/19 17:23:20 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.375 2016/07/20 19:25:39 deraadt Exp $ */ /* * Copyright 2004 Henning Brauer @@ -2586,12 +2586,12 @@ priv_write_file(char *path, int flags, mode_t mode, uid_t uid, gid_t gid, note("Short contents write to '%s' (%zd vs %zu)", path, n, sz); + if (fchown(fd, 0, 0) == -1) + note("fchown(fd, %d, %d) of '%s' failed (%s)", + 0, 0, path, strerror(errno)); if (fchmod(fd, mode) == -1) note("fchmod(fd, 0x%x) of '%s' failed (%s)", mode, path, strerror(errno)); - if (fchown(fd, uid, gid) == -1) - note("fchown(fd, %d, %d) of '%s' failed (%s)", uid, - gid, path, strerror(errno)); close(fd); } -- 2.20.1