Skip to content

Commit

Permalink
expand_user_path: do not look at NULL path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 28, 2014
1 parent 4c0a89f commit 53ec551
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 53ec551

Please sign in to comment.