git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] config.c: NULL check when reading protected config
@ 2022-07-26 17:09 Glen Choo via GitGitGadget
  2022-07-26 17:27 ` Taylor Blau
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Glen Choo via GitGitGadget @ 2022-07-26 17:09 UTC (permalink / raw)
  To: git; +Cc: Glen Choo, Glen Choo

From: Glen Choo <chooglen@google.com>

In read_protected_config(), check whether each file name is NULL before
attempting to read it. This mirrors do_git_config_sequence() (which
read_protected_config() is modelled after).

Without these NULL checks,

 make SANITIZE=address test T=t0410*.sh

fails because xdg_config is NULL, causing us to call fopen(NULL).

Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Glen Choo <chooglen@google.com>
---
    config.c: NULL check when reading protected config
    
    This fixes the SANITIZE=address failure on master, That was introduced
    by gc/bare-repo-discovery. Thanks again to Ævar for the original report
    [1] and for proposing a way to catch this in CI [2].
    
    [1]
    https://lore.kernel.org/git/220725.861qu9oxl4.gmgdl@evledraar.gmail.com
    [2]
    https://lore.kernel.org/git/patch-1.1-e48b6853dd5-20220726T110716Z-avarab@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1299%2Fchooglen%2Fconfig%2Ffix-sanitize-address-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1299/chooglen/config/fix-sanitize-address-v1
Pull-Request: https://github.com/git/git/pull/1299

 config.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index 015bec360f5..b0ba7f439a4 100644
--- a/config.c
+++ b/config.c
@@ -2645,9 +2645,12 @@ static void read_protected_config(void)
 	system_config = git_system_config();
 	git_global_config(&user_config, &xdg_config);
 
-	git_configset_add_file(&protected_config, system_config);
-	git_configset_add_file(&protected_config, xdg_config);
-	git_configset_add_file(&protected_config, user_config);
+	if (system_config)
+		git_configset_add_file(&protected_config, system_config);
+	if (xdg_config)
+		git_configset_add_file(&protected_config, xdg_config);
+	if (user_config)
+		git_configset_add_file(&protected_config, user_config);
 	git_configset_add_parameters(&protected_config);
 
 	free(system_config);

base-commit: 6a475b71f8c4ce708d69fdc9317aefbde3769e25
-- 
gitgitgadget

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

end of thread, other threads:[~2022-07-27 18:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-26 17:09 [PATCH] config.c: NULL check when reading protected config Glen Choo via GitGitGadget
2022-07-26 17:27 ` Taylor Blau
2022-07-26 17:40   ` Glen Choo
2022-07-26 17:43     ` Taylor Blau
2022-07-26 17:51       ` Derrick Stolee
2022-07-26 19:42         ` Glen Choo
2022-07-26 19:03 ` Ævar Arnfjörð Bjarmason
2022-07-26 19:59   ` Glen Choo
2022-07-27  9:08     ` Ævar Arnfjörð Bjarmason
2022-07-26 22:21 ` [PATCH v2] " Glen Choo via GitGitGadget
2022-07-27  9:12   ` nonnull v.s. BUG() if !x (was: [PATCH v2] config.c: NULL check when reading protected config) Ævar Arnfjörð Bjarmason
2022-07-27 17:07     ` Glen Choo
2022-07-27 15:00   ` [PATCH v2] config.c: NULL check when reading protected config Junio C Hamano
2022-07-27 16:52     ` Glen Choo

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).