From: Tobias Stoeckmann Date: Wed, 14 Jan 2026 18:58:40 +0000 (+0100) Subject: vipw: Set ownership, then mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4777ac5421b13e63c5fe4b67e681ab91fa3cd29;p=thirdparty%2Fshadow.git vipw: Set ownership, then mode This is a safer approach, which handles cases in which a file would have less permissions for a group than others. A rare edge case, but let's be safe than sorry. Reported-by: Alejandro Colomar Reviewed-by: Alejandro Colomar Signed-off-by: Tobias Stoeckmann --- diff --git a/src/vipw.c b/src/vipw.c index 5ffd16806..05850423e 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -136,8 +136,8 @@ static int create_backup_file (FILE * fp, char *backup, struct stat *sb) ub.actime = sb->st_atime; ub.modtime = sb->st_mtime; if ( (utime (backup, &ub) != 0) - || (fchmod(fileno(bkfp), sb->st_mode) != 0) - || (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0)) { + || (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0) + || (fchmod(fileno(bkfp), sb->st_mode) != 0)) { fclose(bkfp); unlink (backup); return -1;