From: Stefan Beller <sbeller@google.com>
To: l.s.r@web.de
Cc: git@vger.kernel.org, gitster@pobox.com, jeremy@feusi.co,
pc44800@gmail.com, Stefan Beller <sbeller@google.com>
Subject: [PATCH] submodule: check for NULL return of get_submodule_ref_store()
Date: Wed, 28 Mar 2018 11:38:32 -0700 [thread overview]
Message-ID: <20180328183832.243036-1-sbeller@google.com> (raw)
In-Reply-To: <9c3c0161-f894-3368-ece2-500d0bb6f475@web.de>
From: René Scharfe <l.s.r@web.de>
If we can't find a ref store for a submodule then assume it the latter
is not initialized (or was removed). Print a status line accordingly
instead of causing a segmentation fault by passing NULL as the first
parameter of refs_head_ref().
Reported-by: Jeremy Feusi <jeremy@feusi.co>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
I added a test for you.
Thanks,
Stefan
builtin/submodule--helper.c | 8 ++++++--
t/t7400-submodule-basic.sh | 12 ++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ee020d4749..ae3014ac5a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -654,9 +654,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
displaypath);
} else if (!(flags & OPT_CACHED)) {
struct object_id oid;
+ struct ref_store *refs = get_submodule_ref_store(path);
- if (refs_head_ref(get_submodule_ref_store(path),
- handle_submodule_head_ref, &oid))
+ if (!refs) {
+ print_status(flags, '-', path, ce_oid, displaypath);
+ goto cleanup;
+ }
+ if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
die(_("could not resolve HEAD ref inside the "
"submodule '%s'"), path);
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a39e69a3eb..d8aee51603 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -821,6 +821,18 @@ test_expect_success 'moving the superproject does not break submodules' '
)
'
+test_expect_success 'moving the submodule does not break the superproject' '
+ (
+ cd addtest2 &&
+
+ mv repo repo.bak &&
+ git submodule status >actual &&
+ grep -e "^-" -e repo actual &&
+
+ mv repo.bak repo
+ )
+'
+
test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
(
cd addtest2 &&
--
2.17.0.rc1.321.gba9d0f2565-goog
next prev parent reply other threads:[~2018-03-28 18:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-25 9:50 Null pointer dereference in git-submodule Jeremy Feusi
2018-03-25 10:57 ` René Scharfe
2018-03-27 23:50 ` Stefan Beller
2018-03-28 16:52 ` Junio C Hamano
2018-03-28 17:03 ` Stefan Beller
2018-03-28 18:38 ` Stefan Beller [this message]
2018-03-28 18:57 ` [PATCH] submodule: check for NULL return of get_submodule_ref_store() Eric Sunshine
2018-03-28 20:08 ` Stefan Beller
2018-03-28 20:21 ` Eric Sunshine
2018-03-28 20:54 ` Stefan Beller
2018-03-28 21:14 ` René Scharfe
2018-03-28 21:37 ` Stefan Beller
2018-03-28 22:24 ` René Scharfe
2018-03-28 22:35 ` 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=20180328183832.243036-1-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeremy@feusi.co \
--cc=l.s.r@web.de \
--cc=pc44800@gmail.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).