Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 53ec551

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c0a89f commit 53ec551

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ static struct passwd *getpw_str(const char *username, size_t len)
231231
char *expand_user_path(const char *path)
232232
{
233233
struct strbuf user_path = STRBUF_INIT;
234-
const char *first_slash = strchrnul(path, '/');
235234
const char *to_copy = path;
236235

237236
if (path == NULL)
238237
goto return_null;
239238
if (path[0] == '~') {
239+
const char *first_slash = strchrnul(path, '/');
240240
const char *username = path + 1;
241241
size_t username_len = first_slash - username;
242242
if (username_len == 0) {

0 commit comments

Comments
 (0)