From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <derrickstolee@github.com>,
Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH 3/5] config: add BUG() statement instead of possible segfault
Date: Tue, 27 Sep 2022 14:08:29 +0000 [thread overview]
Message-ID: <f277a7a429db8f54fa06dd1965d62ec491e6d84b.1664287711.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1369.git.1664287711.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>
The git_die_config() method calls git_config_get_value_multi() but
immediately navigates to its first value without checking if the result
is NULL or empty. Callers should only call git_die_config() if there is
at least one value for the given 'key', but such a mistaken use might
slip through. It would be better to show a BUG() statement than a
possible segfault.
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
config.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index bf89afbdab0..0c41606c7d4 100644
--- a/config.c
+++ b/config.c
@@ -2833,8 +2833,13 @@ void git_die_config(const char *key, const char *err, ...)
va_end(params);
}
values = git_config_get_value_multi(key);
- kv_info = values->items[values->nr - 1].util;
- git_die_config_linenr(key, kv_info->filename, kv_info->linenr);
+
+ if (values && values->nr) {
+ kv_info = values->items[values->nr - 1].util;
+ git_die_config_linenr(key, kv_info->filename, kv_info->linenr);
+ } else {
+ BUG("expected a non-empty list of values");
+ }
}
/*
--
gitgitgadget
next prev parent reply other threads:[~2022-09-27 14:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 14:08 [PATCH 0/5] [RFC] config API: return empty list, not NULL Derrick Stolee via GitGitGadget
2022-09-27 14:08 ` [PATCH 1/5] config: relax requirements on multi-value return Derrick Stolee via GitGitGadget
2022-09-27 17:26 ` Junio C Hamano
2022-09-27 14:08 ` [PATCH 2/5] *: relax git_configset_get_value_multi result Derrick Stolee via GitGitGadget
2022-09-28 15:58 ` Taylor Blau
2022-09-27 14:08 ` Derrick Stolee via GitGitGadget [this message]
2022-09-27 16:17 ` [PATCH 3/5] config: add BUG() statement instead of possible segfault Ævar Arnfjörð Bjarmason
2022-09-27 16:46 ` Derrick Stolee
2022-09-27 17:22 ` Ævar Arnfjörð Bjarmason
2022-09-27 14:08 ` [PATCH 4/5] config: return an empty list, not NULL Derrick Stolee via GitGitGadget
2022-09-27 16:21 ` Ævar Arnfjörð Bjarmason
2022-09-27 16:50 ` Derrick Stolee
2022-09-27 19:18 ` Ævar Arnfjörð Bjarmason
2022-09-28 13:46 ` Derrick Stolee
2022-09-28 14:37 ` Ævar Arnfjörð Bjarmason
2022-09-28 18:10 ` Derrick Stolee
2022-09-28 19:33 ` Ævar Arnfjörð Bjarmason
2022-09-27 14:08 ` [PATCH 5/5] *: expect a non-NULL list of config values Derrick Stolee via GitGitGadget
2022-09-28 2:40 ` [PATCH 0/5] [RFC] config API: return empty list, not NULL Junio C Hamano
2022-09-28 18:38 ` Derrick Stolee
2022-09-28 19:27 ` Ævar Arnfjörð Bjarmason
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=f277a7a429db8f54fa06dd1965d62ec491e6d84b.1664287711.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
/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).