From: "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Han-Wen Nienhuys" <hanwen@google.com>,
"Jonathan Tan" <jonathantanmy@google.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Han-Wen Nienhuys" <hanwenn@gmail.com>,
"Han-Wen Nienhuys" <hanwen@google.com>
Subject: [PATCH] fixup! propagate errno from failing read
Date: Tue, 17 Aug 2021 12:31:29 +0000 [thread overview]
Message-ID: <pull.1068.git.git.1629203489546.gitgitgadget@gmail.com> (raw)
From: Han-Wen Nienhuys <hanwen@google.com>
This fixes a crash triggered by the BUG() statement.
This can occur with symlinked .git/refs. To check availability,
refs_verify_refname_available will run refs_read_raw_ref() on each prefix,
leading to a read() from .git/refs (which is a directory).
When handling the symlink case, it is probably more robust to re-issue the
lstat() as a normal stat(), in which case, we would fall back to the directory
case.
For now, propagating errno from strbuf_read() is simpler and avoids the crash.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
fixup! propagate errno from failing read
This fixes a crash triggered by the BUG() statement.
This can occur with symlinked .git/refs. To check availability,
refs_verify_refname_available will run refs_read_raw_ref() on each
prefix, leading to a read() from .git/refs (which is a directory).
When handling the symlink case, it is probably more robust to re-issue
the lstat() as a normal stat(), in which case, we would fall back to the
directory case.
For now, propagating errno from strbuf_read() is simpler and avoids the
crash.
Signed-off-by: Han-Wen Nienhuys hanwen@google.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1068%2Fhanwen%2Ffiles-fixup-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1068/hanwen/files-fixup-v1
Pull-Request: https://github.com/git/git/pull/1068
refs/files-backend.c | 1 +
t/t3200-branch.sh | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0d96eeba61b..f546cc3cc3d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -454,6 +454,7 @@ stat_ref:
}
strbuf_reset(&sb_contents);
if (strbuf_read(&sb_contents, fd, 256) < 0) {
+ myerr = errno;
close(fd);
goto out;
}
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index cc4b10236e2..dd17718160a 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -109,6 +109,20 @@ test_expect_success 'git branch -m n/n n should work' '
git reflog exists refs/heads/n
'
+test_expect_success 'git branch -m with symlinked .git/refs' '
+ git init subdir &&
+ test_when_finished "rm -rf subdir" &&
+ (cd subdir &&
+ for d in refs objects packed-refs ; do
+ rm -rf .git/$d &&
+ ln -s ../../.git/$d .git/$d ; done ) &&
+ git --git-dir subdir/.git/ branch rename-src &&
+ expect=$(git rev-parse rename-src) &&
+ git --git-dir subdir/.git/ branch -m rename-src rename-dest &&
+ test $(git rev-parse rename-dest) = "$expect" &&
+ git branch -D rename-dest
+'
+
# The topmost entry in reflog for branch bbb is about branch creation.
# Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
base-commit: f000ecbed922c727382651490e75014f003c89ca
--
gitgitgadget
next reply other threads:[~2021-08-17 12:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 12:31 Han-Wen Nienhuys via GitGitGadget [this message]
2021-08-17 16:14 ` [PATCH] fixup! propagate errno from failing read Jonathan Tan
2021-08-18 22:19 ` Jonathan Nieder
2021-08-17 22:38 ` Junio C Hamano
2021-08-18 9:00 ` Han-Wen Nienhuys
2021-08-18 18:30 ` Junio C Hamano
2021-08-19 0:11 ` Junio C Hamano
2021-08-19 9:01 ` Han-Wen Nienhuys
2021-08-19 3:55 ` Jeff King
2021-08-19 5:01 ` [PATCH] t3200: refactor symlink test Carlo Marcelo Arenas Belón
2021-08-19 5:51 ` Eric Sunshine
2021-08-19 7:52 ` [PATCH v2] t3200: refactor symlink test from hn/refs-errno-cleanup Carlo Marcelo Arenas Belón
2021-08-19 20:26 ` Junio C Hamano
2021-08-19 20:26 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1068.git.git.1629203489546.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
--cc=hanwenn@gmail.com \
--cc=jonathantanmy@google.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).