Skip to content

Commit 671bbf7

Browse files
committed
adjust_shared_perm(): leave g+s alone when the group does not matter
Julien Moutinho reports that in an environment where directory does not have BSD group semantics and requires the g+s to be set (aka FORCE_DIR_SET_GID), but the system forbids chmod() to touch the g+s bit, adjust_shared_perm() fails even when the repository is for private use with perm = 0600, because we unconditionally try to set the g+s bit. When we grant extra access based on group membership (i.e. the directory has either g+r or g+w bit set), which group the directory and its contents are owned by matters. But otherwise (e.g. perm is set to 0600, in Julien's case), flipping g+s bit is not necessary. Reported-by: Julien Moutinho <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63bba4f commit 671bbf7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

path.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,13 @@ int adjust_shared_perm(const char *path)
901901
if (S_ISDIR(old_mode)) {
902902
/* Copy read bits to execute bits */
903903
new_mode |= (new_mode & 0444) >> 2;
904-
new_mode |= FORCE_DIR_SET_GID;
904+
905+
/*
906+
* g+s matters only if any extra access is granted
907+
* based on group membership.
908+
*/
909+
if (FORCE_DIR_SET_GID && (new_mode & 060))
910+
new_mode |= FORCE_DIR_SET_GID;
905911
}
906912

907913
if (((old_mode ^ new_mode) & ~S_IFMT) &&

0 commit comments

Comments
 (0)