summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-06-07 11:22:16 -0400
committerNick Mathewson <nickm@torproject.org>2010-06-07 11:22:16 -0400
commit2aa6fc5ae87985dd0555d98e545bdf2f83a93c49 (patch)
treed28072e3edf51007bfd530327ce111b4643dccee /src
parent50afadb74d1de2d2c03d569c237f171b88f7bc25 (diff)
parent03ea5f930eca089c8631c7236527f59195fbd0eb (diff)
downloadtor-2aa6fc5ae87985dd0555d98e545bdf2f83a93c49.tar.gz
tor-2aa6fc5ae87985dd0555d98e545bdf2f83a93c49.zip
Merge branch 'bug1522'
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/common/util.c b/src/common/util.c
index fe48e93284..f5001abe6c 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2317,18 +2317,18 @@ expand_filename(const char *filename)
return tor_strdup(filename);
#else
if (*filename == '~') {
- size_t len;
- char *home, *result;
+ char *home, *result=NULL;
const char *rest;
if (filename[1] == '/' || filename[1] == '\0') {
home = getenv("HOME");
if (!home) {
log_warn(LD_CONFIG, "Couldn't find $HOME environment variable while "
- "expanding \"%s\"", filename);
- return NULL;
+ "expanding \"%s\"; defaulting to \"\".", filename);
+ home = tor_strdup("");
+ } else {
+ home = tor_strdup(home);
}
- home = tor_strdup(home);
rest = strlen(filename)>=2?(filename+2):"";
} else {
#ifdef HAVE_PWD_H
@@ -2355,11 +2355,7 @@ expand_filename(const char *filename)
if (strlen(home)>1 && !strcmpend(home,PATH_SEPARATOR)) {
home[strlen(home)-1] = '\0';
}
- /* Plus one for /, plus one for NUL.
- * 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"PATH_SEPARATOR"%s",home,rest);
+ tor_asprintf(&result,"%s"PATH_SEPARATOR"%s",home,rest);
tor_free(home);
return result;
} else {