From c2f699cc6bfb241c97cc53dfe6bfd0ea0385456c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 5 Nov 2006 06:20:49 +0000 Subject: [PATCH] Make sure that any weird mode bits (if they exist up beyond the format bits) can't cause problems for the mode comparisons in set_stat_xattr(). --- fake-super.diff | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fake-super.diff b/fake-super.diff index 77a26dd..a5d1c5b 100644 --- a/fake-super.diff +++ b/fake-super.diff @@ -512,7 +512,7 @@ above: rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count); rxa->name = name; rxa->datum = ptr; -@@ -412,4 +435,146 @@ int set_xattr(const char *fname, const s +@@ -412,4 +435,149 @@ int set_xattr(const char *fname, const s return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */ } @@ -572,7 +572,7 @@ above: +{ + STRUCT_STAT fst, xst; + dev_t rdev; -+ mode_t mode; ++ mode_t mode, fmode; + + if (dry_run) + return 0; @@ -589,20 +589,23 @@ above: + return -1; + } + -+ if (IS_DEVICE(file->mode) || IS_SPECIAL(file->mode)) ++ fst.st_mode &= (_S_IFMT | CHMOD_BITS); ++ fmode = file->mode & (_S_IFMT | CHMOD_BITS); ++ ++ if (IS_DEVICE(fmode) || IS_SPECIAL(fmode)) + rdev = file->u.rdev; + else + rdev = 0; + + /* Dump the special permissions and enable full owner access. */ -+ mode = (fst.st_mode & ~CHMOD_BITS) | (file->mode & ACCESSPERMS) ++ mode = (fst.st_mode & _S_IFMT) | (fmode & ACCESSPERMS) + | (S_ISDIR(fst.st_mode) ? 0700 : 0600); + if (fst.st_mode != mode) + do_chmod(fname, mode); + if (!IS_DEVICE(fst.st_mode) && !IS_SPECIAL(fst.st_mode)) + fst.st_rdev = 0; /* just in case */ + -+ if (mode == file->mode && fst.st_rdev == rdev ++ if (mode == fmode && fst.st_rdev == rdev + && fst.st_uid == file->uid && fst.st_gid == file->gid) { + /* xst.st_mode will be 0 if there's no current stat xattr */ + if (xst.st_mode && sys_lremovexattr(fname, XSTAT_ATTR) < 0) { @@ -614,11 +617,11 @@ above: + return 0; + } + -+ if (xst.st_mode != file->mode || xst.st_rdev != rdev ++ if (xst.st_mode != fmode || xst.st_rdev != rdev + || xst.st_uid != file->uid || xst.st_gid != file->gid) { + char buf[256]; + int len = snprintf(buf, sizeof buf, "%o %u,%u %u:%u", -+ to_wire_mode(file->mode) & (_S_IFMT|CHMOD_BITS), ++ to_wire_mode(fmode), + (int)major(rdev), (int)minor(rdev), + (int)file->uid, (int)file->gid); + if (sys_lsetxattr(fname, XSTAT_ATTR, buf, len) < 0) { -- 2.34.1