Skip to content

Commit f4777ac

Browse files
stoeckmannalejandro-colomar
authored andcommitted
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 <alx@kernel.org> Reviewed-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
1 parent 976b7bf commit f4777ac

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/vipw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ static int create_backup_file (FILE * fp, char *backup, struct stat *sb)
136136
ub.actime = sb->st_atime;
137137
ub.modtime = sb->st_mtime;
138138
if ( (utime (backup, &ub) != 0)
139-
|| (fchmod(fileno(bkfp), sb->st_mode) != 0)
140-
|| (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0)) {
139+
|| (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0)
140+
|| (fchmod(fileno(bkfp), sb->st_mode) != 0)) {
141141
fclose(bkfp);
142142
unlink (backup);
143143
return -1;

0 commit comments

Comments
 (0)