aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-01-27 20:36:12 -0500
committerJunio C Hamano <gitster@pobox.com>2014-01-28 11:59:47 -0800
commit53ec551c87c731c5c4171e943842998bdfb5548e (patch)
tree8a7d9b6385a7987b28392f33f2299b2399e03c65 /path.c
parent4c0a89fcde219df8db8fdb9635ef2ef40d002a6e (diff)
downloadgit-53ec551c87c731c5c4171e943842998bdfb5548e.tar.gz
git-53ec551c87c731c5c4171e943842998bdfb5548e.tar.xz
expand_user_path: do not look at NULL path
We explicitly check for and handle the case that the incoming "path" variable is NULL, but before doing so we call strchrnul on it, leading to a potential segfault. We can fix this simply by moving the strchrnul call down; as a bonus, we can tighten the scope on the associated variable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/path.c b/path.c
index 6f2aa699a..3a5796156 100644
--- a/path.c
+++ b/path.c
@@ -231,12 +231,12 @@ static struct passwd *getpw_str(const char *username, size_t len)
char *expand_user_path(const char *path)
{
struct strbuf user_path = STRBUF_INIT;
- const char *first_slash = strchrnul(path, '/');
const char *to_copy = path;
if (path == NULL)
goto return_null;
if (path[0] == '~') {
+ const char *first_slash = strchrnul(path, '/');
const char *username = path + 1;
size_t username_len = first_slash - username;
if (username_len == 0) {