[or-cvs] fix some local buffer overflows

Roger Dingledine arma at seul.org
Tue Sep 28 22:38:24 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	dirserv.c routerlist.c 
Log Message:
fix some local buffer overflows
fix a memory leak


Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- dirserv.c	28 Sep 2004 22:24:56 -0000	1.83
+++ dirserv.c	28 Sep 2004 22:38:21 -0000	1.84
@@ -677,7 +677,7 @@
     }
     cached_directory_published = when;
     if(get_data_directory(&options)) {
-      sprintf(filename,"%s/cached-directory", get_data_directory(&options));
+      snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options));
       if(write_str_to_file(filename,cached_directory,0) < 0) {
         log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
       }
@@ -751,7 +751,7 @@
   }
   free(new_directory);
   if(get_data_directory(&options)) {
-    sprintf(filename,"%s/cached-directory", get_data_directory(&options));
+    snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options));
     if(write_str_to_file(filename,the_directory,0) < 0) {
       log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
     }

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- routerlist.c	21 Sep 2004 17:14:47 -0000	1.139
+++ routerlist.c	28 Sep 2004 22:38:21 -0000	1.140
@@ -49,23 +49,26 @@
   char filename[512];
   routerlist_clear_trusted_directories();
   if (options.RouterFile) {
+    log_fn(LOG_INFO, "Loading router list from %s", options.RouterFile);
     if (router_load_routerlist_from_file(options.RouterFile, 1) < 0) {
-      log_fn(LOG_ERR,"Error loading router list.");
+      log_fn(LOG_ERR,"Error loading router list '%s'.", options.RouterFile);
       return -1;
     }
   } else {
+    log_fn(LOG_INFO, "Loading internal default router list.");
     if (config_assign_default_dirservers() < 0)
       return -1;
   }
   if (get_data_directory(&options)) {
     char *s;
-    sprintf(filename,"%s/cached-directory", get_data_directory(&options));
+    snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options));
     s = read_file_to_str(filename,0);
     if (s) {
       log_fn(LOG_INFO, "Loading cached directory from %s", filename);
       if (router_load_routerlist_from_string(s, 0) < 0) {
-        log_fn(LOG_WARN, "Cached directory was unparseable; ignoring.");
+        log_fn(LOG_WARN, "Cached directory '%s' was unparseable; ignoring.", filename);
       }
+      tor_free(s);
     }
   }
   return 0;



More information about the tor-commits mailing list