git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sha1_file.c: make sure open_sha1_file does not open a directory
@ 2015-02-08 23:05 Kyle J. McKay
  2015-02-09  0:54 ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Kyle J. McKay @ 2015-02-08 23:05 UTC (permalink / raw)
  To: Jeff King, Jonathon Mah, Junio C Hamano; +Cc: Git mailing list

Since "sha1_file: fix iterating loose alternate objects", it's possible
for the base member of the alt_odb_list structure to be NUL terminated
rather than ending with a '/' when open_sha1_file is called.

Unfortunately this causes a directory to be passed to git_open_noatime
instead of a file which it happily opens and returns whereupon this
open directory file handle is then passed to mmap.

mmap does not like this and fails with an invalid argument error
at which point the pack-objects process dies prematurely.

To avoid this we preserve the last character of the base member,
set it to '/', make the git_open_noatime call and then restore
it to its previous value which allows pack-objects to function properly.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
---

*****

While this patch can be applied without "sha1_file: fix iterating
loose alternate objects" you cannot even get to the failure this fixes
without first having that patch applied.

All this stuffing of a single char back and forth into a [-1] index
seems awfully kludgy to me.

However, without this fix and the previous sha1_file fix I would need
to jettison the latest stuff and revert back to 2.1.4.

I suggest that this (or another fix for the problem) go into maint
together with the "sha1_file: fix iterating loose alternate objects"
fix.

*****

 sha1_file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sha1_file.c b/sha1_file.c
index f575b3cf..235f6ad8 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1491,8 +1491,11 @@ static int open_sha1_file(const unsigned char *sha1)
 
 	prepare_alt_odb();
 	for (alt = alt_odb_list; alt; alt = alt->next) {
+		char c = alt->name[-1];
+		alt->name[-1] = '/';
 		fill_sha1_path(alt->name, sha1);
 		fd = git_open_noatime(alt->base);
+		alt->name[-1] = c;
 		if (fd >= 0)
 			return fd;
 		if (most_interesting_errno == ENOENT)
--

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-09 18:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-08 23:05 [PATCH] sha1_file.c: make sure open_sha1_file does not open a directory Kyle J. McKay
2015-02-09  0:54 ` Jeff King
2015-02-09  1:12   ` Jeff King
2015-02-09  1:13     ` [PATCH 1/2] for_each_loose_file_in_objdir: take an optional strbuf path Jeff King
2015-02-09  1:15     ` [PATCH 2/2] sha1_file: fix iterating loose alternate objects Jeff King
2015-02-09  9:44       ` Kyle J. McKay
2015-02-09 18:48   ` [PATCH] sha1_file.c: make sure open_sha1_file does not open a directory Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).