r15320@catbus: nickm | 2007-09-24 11:49:09 -0400

Backport r11332: fix a user-triggerable segfault in expand_filename("~").


svn:r11608
This commit is contained in:
Nick Mathewson
2007-09-24 15:53:51 +00:00
parent 3115905506
commit 2cd6a240bd
3 changed files with 6 additions and 4 deletions
+3 -3
View File
@@ -1555,7 +1555,7 @@ expand_filename(const char *filename)
return NULL;
}
home = tor_strdup(home);
rest = strlen(filename)>=2?(filename+2):NULL;
rest = strlen(filename)>=2?(filename+2):"";
} else {
#ifdef HAVE_PWD_H
char *username, *slash;
@@ -1570,7 +1570,7 @@ expand_filename(const char *filename)
return NULL;
}
tor_free(username);
rest = slash ? (slash+1) : NULL;
rest = slash ? (slash+1) : "";
#else
log_warn(LD_CONFIG, "Couldn't expend homedir on system without pwd.h");
return tor_strdup(filename);
@@ -1585,7 +1585,7 @@ expand_filename(const char *filename)
* Round up to 16 in case we can't do math. */
len = strlen(home)+strlen(rest)+16;
result = tor_malloc(len);
tor_snprintf(result,len,"%s/%s",home,rest?rest:"");
tor_snprintf(result,len,"%s/%s",home,rest);
tor_free(home);
return result;
} else {