[or-cvs] r11332: Fix a segfault in expand_filename("~"). Found by lindi. (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Fri Aug 31 12:51:52 UTC 2007


Author: nickm
Date: 2007-08-31 08:51:52 -0400 (Fri, 31 Aug 2007)
New Revision: 11332

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/common/util.c
Log:
 r14869 at catbus:  nickm | 2007-08-31 08:49:26 -0400
 Fix a segfault in expand_filename("~").  Found by lindi.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14869] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-08-31 11:20:23 UTC (rev 11331)
+++ tor/trunk/ChangeLog	2007-08-31 12:51:52 UTC (rev 11332)
@@ -19,6 +19,8 @@
       bug 467.
     - On OSX, stop warning the user that kqueue support in libevent is
       "experimental", since it seems to have worked fine for ages.
+    - Fix a user-triggerable segfault in expand_filename().  (There isn't
+      a way to trigger this remotely.)
 
   o Code simplifications and refactoring:
     - Revamp file-writing logic so we don't need to have the entire contents

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2007-08-31 11:20:23 UTC (rev 11331)
+++ tor/trunk/src/common/util.c	2007-08-31 12:51:52 UTC (rev 11332)
@@ -1839,7 +1839,7 @@
         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;
@@ -1854,7 +1854,7 @@
         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);
@@ -1869,7 +1869,7 @@
      * 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?rest:"");
+    tor_snprintf(result,len,"%s"PATH_SEPARATOR"%s",home,rest);
     tor_free(home);
     return result;
   } else {



More information about the tor-commits mailing list