[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/master 2/2] Reinstate warning when HOME isn't set.



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon, 7 Jun 2010 11:20:39 -0400
Subject: Reinstate warning when HOME isn't set.
Commit: 03ea5f930eca089c8631c7236527f59195fbd0eb

Having ~/.tor expand into /.tor is, after all, almost certainly not
what the user wanted, and it deserves a warning message.

Also, convert a guess-and-malloc-and-sprintf triple into an asprintf.
---
 src/common/util.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 748e23b..f5001ab 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2317,16 +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)
+      if (!home) {
+        log_warn(LD_CONFIG, "Couldn't find $HOME environment variable while "
+                 "expanding \"%s\"; defaulting to \"\".", filename);
         home = tor_strdup("");
-      else
+      } else {
         home = tor_strdup(home);
+      }
       rest = strlen(filename)>=2?(filename+2):"";
     } else {
 #ifdef HAVE_PWD_H
@@ -2353,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 {
-- 
1.6.5