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>
Jeff King committed
Jan 27, 2014 at 20:36 UTC
53ec551c87c731c5c4171e943842998bdfb5548e
1 file changed
+1
-1
path.c
+1
-1
@@ -231,12 +231,12 @@ static struct passwd *getpw_str(const char *username, size_t len)
231
char *expand_user_path(const char *path)
232
{
233
struct strbuf user_path = STRBUF_INIT;
234
- const char *first_slash = strchrnul(path, '/');
234
const char *to_copy = path;
235
236
if (path == NULL)
237
goto return_null;
238
if (path[0] == '~') {
239
+ const char *first_slash = strchrnul(path, '/');
240
const char *username = path + 1;
241
size_t username_len = first_slash - username;
242
if (username_len == 0) {