From 557a1fa25a0a1d60bdb71ea3ad0e4e9a9cd9cc61 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Tue, 17 Sep 2013 17:39:10 -0400 Subject: [PATCH] Ignore the contents of a default .git/description file --- src/main/java/com/gitblit/utils/JGitUtils.java | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java index 66dbd60..cf6ec26 100644 --- a/src/main/java/com/gitblit/utils/JGitUtils.java +++ b/src/main/java/com/gitblit/utils/JGitUtils.java @@ -403,8 +403,22 @@ if (! path.exists()) return -1; int perm = configShared.getPerm(); - int mode = JnaUtils.getFilemode(path); + JnaUtils.Filestat stat = JnaUtils.getFilestat(path); + if (stat == null) return -1; + int mode = stat.mode; if (mode < 0) return -1; + + // Now, here is the kicker: Under Linux, chmod'ing a sgid file whose guid is different from the process' + // effective guid will reset the sgid flag of the file. Since there is no way to get the sgid flag back in + // that case, we decide to rather not touch is and getting the right permissions will have to be achieved + // in a different way, e.g. by using an appropriate umask for the Gitblit process. + if (System.getProperty("os.name").toLowerCase().startsWith("linux")) { + if ( ((mode & (JnaUtils.S_ISGID | JnaUtils.S_ISUID)) != 0) + && stat.gid != JnaUtils.getegid() ) { + LOGGER.debug("Not adjusting permissions to prevent clearing suid/sgid bits for '" + path + "'" ); + return 0; + } + } // If the owner has no write access, delete it from group and other, too. if ((mode & JnaUtils.S_IWUSR) == 0) perm &= ~0222; @@ -728,6 +742,8 @@ try { if (tree == null) { ObjectId object = getDefaultBranch(repository); + if (object == null) + return null; RevCommit commit = rw.parseCommit(object); tree = commit.getTree(); } -- Gitblit v1.9.1