From: "Kyle J. McKay" <mackyle@gmail.com>
To: Jeff King <peff@peff.net>, Jonathon Mah <me@jonathonmah.com>,
Junio C Hamano <gitster@pobox.com>
Cc: Git mailing list <git@vger.kernel.org>
Subject: [PATCH] sha1_file.c: make sure open_sha1_file does not open a directory
Date: Sun, 8 Feb 2015 15:05:32 -0800 [thread overview]
Message-ID: <b0993cc1fcac290d7506b24942af300@74d39fa044aa309eaea14b9f57fe79c> (raw)
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)
--
next reply other threads:[~2015-02-08 23:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-08 23:05 Kyle J. McKay [this message]
2015-02-09 0:54 ` [PATCH] sha1_file.c: make sure open_sha1_file does not open a directory 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b0993cc1fcac290d7506b24942af300@74d39fa044aa309eaea14b9f57fe79c \
--to=mackyle@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@jonathonmah.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).