]> git.ipfire.org Git - thirdparty/git.git/commit
var: avoid a segmentation fault when `HOME` is unset
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 4 Sep 2023 06:21:26 +0000 (06:21 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Sep 2023 22:28:26 +0000 (15:28 -0700)
commit256a94ef6c8c0c94f9629a1ffe893577ccef8efd
tree43cf7cad9d7d2c1d27f725eb11b4b819f5a569e7
parented773a18c6e92ae4f4e016f4529d6bdfbbbd56d8
var: avoid a segmentation fault when `HOME` is unset

The code introduced in 576a37fccbf (var: add attributes files locations,
2023-06-27) paid careful attention to use `xstrdup()` for pointers known
never to be `NULL`, and `xstrdup_or_null()` otherwise.

One spot was missed, though: `git_attr_global_file()` can return `NULL`,
when the `HOME` variable is not set (and neither `XDG_CONFIG_HOME`), a
scenario not too uncommon in certain server scenarios.

Fix this, and add a test case to avoid future regressions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/var.c
t/t0007-git-var.sh