[PATCH] Do not take mode bits from index after type change.

Previous thread: [PATCH] A new merge stragety 'subtree'. by Junio C Hamano on Friday, February 16, 2007 - 6:49 pm. (9 messages)

Next thread: Re: [PATCH] Add git-unbundle - unpack objects and references for disconnected transfer by Junio C Hamano on Friday, February 16, 2007 - 11:57 pm. (3 messages)
From: Junio C Hamano
Date: Friday, February 16, 2007 - 11:56 pm

When we do not trust executable bit from lstat(2), we copied
existing ce_mode bits without checking if the filesystem object
is a regular file (which is the only thing we apply the "trust
executable bit" business) nor if the blob in the index is a
regular file (otherwise, we should do the same as registering a
new regular file, which is to default non-executable).

Noticed by Johannes Sixt.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * Adds a test -- how about this as a replacement?

 builtin-apply.c        |    2 +-
 builtin-update-index.c |   13 +++++++------
 cache.h                |   10 ++++++++++
 diff-lib.c             |    4 +---
 read-cache.c           |   13 +++++++------
 t/t3700-add.sh         |   20 ++++++++++++++++++++
 6 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 3fefdac..abe3538 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1988,7 +1988,7 @@ static int check_patch(struct patch *patch, struct patch *prev_patch)
 			return error("%s: %s", old_name, strerror(errno));
 
 		if (!cached)
-			st_mode = ntohl(create_ce_mode(st.st_mode));
+			st_mode = ntohl(ce_mode_from_stat(ce, st.st_mode));
 
 		if (patch->is_new < 0)
 			patch->is_new = 0;
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 1ac613a..772aaba 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -109,16 +109,17 @@ static int add_file_to_cache(const char *path)
 	ce->ce_flags = htons(namelen);
 	fill_stat_cache_info(ce, &st);
 
-	ce->ce_mode = create_ce_mode(st.st_mode);
-	if (!trust_executable_bit) {
+	if (trust_executable_bit)
+		ce->ce_mode = create_ce_mode(st.st_mode);
+	else {
 		/* If there is an existing entry, pick the mode bits
 		 * from it, otherwise assume unexecutable.
 		 */
+		struct cache_entry *ent;
 		int pos = cache_name_pos(path, namelen);
-		if (0 <= pos)
-			ce->ce_mode = active_cache[pos]->ce_mode;
-		else if (S_ISREG(st.st_mode))
-			ce->ce_mode = ...
From: Johannes Sixt
Date: Saturday, February 17, 2007 - 3:31 am

Your patch works here, too. Thanks!

I'd appreciate if you could publish it soon since it has a few conflicts with 
my current "don't trust symlinks" work.

-- Hannes
-

From: Junio C Hamano
Date: Saturday, February 17, 2007 - 10:49 am

I think this bugfix should go to 'maint' and in 'master'.  I
tried to be careful, but extra sets of eyeballs to double-check
that I did not break anything are certainly appreciated.


-

Previous thread: [PATCH] A new merge stragety 'subtree'. by Junio C Hamano on Friday, February 16, 2007 - 6:49 pm. (9 messages)

Next thread: Re: [PATCH] Add git-unbundle - unpack objects and references for disconnected transfer by Junio C Hamano on Friday, February 16, 2007 - 11:57 pm. (3 messages)