{"thread":{"id":"60192","subject":"[PATCH] var: avoid a segmentation fault when `HOME` is unset","startedAt":"2023-09-04T06:21:34Z","lastAt":"2023-09-05T16:03:31Z","messageCount":3,"participants":["Johannes Schindelin via GitGitGadget","brian m. carlson","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"481360","messageId":"pull.1580.git.1693808487058.gitgitgadget@gmail.com","threadId":"60192","inReplyTo":null,"subject":"[PATCH] var: avoid a segmentation fault when `HOME` is unset","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-09-04T06:21:26Z","receivedAt":"2023-09-04T06:21:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe code introduced in 576a37fccbf (var: add attributes files locations,\n2023-06-27) paid careful attention to use `xstrdup()` for pointers known\nnever to be `NULL`, and `xstrdup_or_null()` otherwise.\n\nOne spot was missed, though: `git_attr_global_file()` can return `NULL`,\nwhen the `HOME` variable is not set (and neither `XDG_CONFIG_HOME`), a\nscenario not too uncommon in certain server scenarios.\n\nFix this, and add a test case to avoid future regressions.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    var: avoid a segmentation fault when HOME is unset\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1580%2Fdscho%2Favoid-segfault-in-git-var-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1580/dscho/avoid-segfault-in-git-var-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1580\n\n builtin/var.c      | 2 +-\n t/t0007-git-var.sh | 9 +++++++++\n 2 files changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/var.c b/builtin/var.c\nindex 74161bdf1c6..8cf7dd9e2e5 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -66,7 +66,7 @@ static char *git_attr_val_system(int ident_flag UNUSED)\n \n static char *git_attr_val_global(int ident_flag UNUSED)\n {\n-\tchar *file = xstrdup(git_attr_global_file());\n+\tchar *file = xstrdup_or_null(git_attr_global_file());\n \tif (file) {\n \t\tnormalize_path_copy(file, file);\n \t\treturn file;\ndiff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh\nindex 8cb597f99c4..ff4fd9348cc 100755\n--- a/t/t0007-git-var.sh\n+++ b/t/t0007-git-var.sh\n@@ -268,4 +268,13 @@ test_expect_success 'listing and asking for variables are exclusive' '\n \ttest_must_fail git var -l GIT_COMMITTER_IDENT\n '\n \n+test_expect_success '`git var -l` works even without HOME' '\n+\t(\n+\t\tXDG_CONFIG_HOME= &&\n+\t\texport XDG_CONFIG_HOME &&\n+\t\tunset HOME &&\n+\t\tgit var -l\n+\t)\n+'\n+\n test_done\n\nbase-commit: 43c8a30d150ecede9709c1f2527c8fba92c65f40\n-- \ngitgitgadget\n"},{"id":"481377","messageId":"ZPY9j0XDt/VVMnhG@tapette.crustytoothpaste.net","threadId":"60192","inReplyTo":"pull.1580.git.1693808487058.gitgitgadget@gmail.com","subject":"Re: [PATCH] var: avoid a segmentation fault when `HOME` is unset","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-09-04T20:26:55Z","receivedAt":"2023-09-04T20:27:07Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2023-09-04 at 06:21:26, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> The code introduced in 576a37fccbf (var: add attributes files locations,\n> 2023-06-27) paid careful attention to use `xstrdup()` for pointers known\n> never to be `NULL`, and `xstrdup_or_null()` otherwise.\n> \n> One spot was missed, though: `git_attr_global_file()` can return `NULL`,\n> when the `HOME` variable is not set (and neither `XDG_CONFIG_HOME`), a\n> scenario not too uncommon in certain server scenarios.\n> \n> Fix this, and add a test case to avoid future regressions.\n\nLooks good to me.  Thanks for the patch, and my apologies for the\noversight.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"481399","messageId":"d43d0b9d-6e97-94e6-2843-e6025142f963@gmx.de","threadId":"60192","inReplyTo":"ZPY9j0XDt/VVMnhG@tapette.crustytoothpaste.net","subject":"Re: [PATCH] var: avoid a segmentation fault when `HOME` is unset","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2023-09-05T10:58:05Z","receivedAt":"2023-09-05T16:03:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi brian,\n\nOn Mon, 4 Sep 2023, brian m. carlson wrote:\n\n> On 2023-09-04 at 06:21:26, Johannes Schindelin via GitGitGadget wrote:\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > The code introduced in 576a37fccbf (var: add attributes files locations,\n> > 2023-06-27) paid careful attention to use `xstrdup()` for pointers known\n> > never to be `NULL`, and `xstrdup_or_null()` otherwise.\n> >\n> > One spot was missed, though: `git_attr_global_file()` can return `NULL`,\n> > when the `HOME` variable is not set (and neither `XDG_CONFIG_HOME`), a\n> > scenario not too uncommon in certain server scenarios.\n> >\n> > Fix this, and add a test case to avoid future regressions.\n>\n> Looks good to me.\n\nThank you for the review.\n\nCiao,\nJohannes\n"}]}