]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
vipw: Set ownership, then mode
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 14 Jan 2026 18:58:40 +0000 (19:58 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Wed, 14 Jan 2026 19:56:24 +0000 (20:56 +0100)
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>
src/vipw.c

index 5ffd168060353116f1a92f6274f932928025355f..05850423e7f2688b52822600ed6e3faf2271d006 100644 (file)
@@ -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;