var: avoid a segmentation fault when HOME
is unset
The code introduced in 576a37fccb
(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>
This commit is contained in:

committed by
Junio C Hamano

parent
ed773a18c6
commit
256a94ef6c
@ -64,7 +64,7 @@ static char *git_attr_val_system(int ident_flag UNUSED)
|
||||
|
||||
static char *git_attr_val_global(int ident_flag UNUSED)
|
||||
{
|
||||
char *file = xstrdup(git_attr_global_file());
|
||||
char *file = xstrdup_or_null(git_attr_global_file());
|
||||
if (file) {
|
||||
normalize_path_copy(file, file);
|
||||
return file;
|
||||
|
Reference in New Issue
Block a user