fix some local buffer overflows

fix a memory leak


svn:r2391
This commit is contained in:
Roger Dingledine 2004-09-28 22:38:21 +00:00
parent 7eff786e4b
commit 4b3001a08c
2 changed files with 8 additions and 5 deletions

View File

@ -677,7 +677,7 @@ void dirserv_set_cached_directory(const char *directory, time_t when)
} }
cached_directory_published = when; cached_directory_published = when;
if(get_data_directory(&options)) { 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) { if(write_str_to_file(filename,cached_directory,0) < 0) {
log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring."); log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
} }
@ -751,7 +751,7 @@ static int dirserv_regenerate_directory(void)
} }
free(new_directory); free(new_directory);
if(get_data_directory(&options)) { 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) { if(write_str_to_file(filename,the_directory,0) < 0) {
log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring."); log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
} }

View File

@ -49,23 +49,26 @@ int router_reload_router_list(void)
char filename[512]; char filename[512];
routerlist_clear_trusted_directories(); routerlist_clear_trusted_directories();
if (options.RouterFile) { if (options.RouterFile) {
log_fn(LOG_INFO, "Loading router list from %s", options.RouterFile);
if (router_load_routerlist_from_file(options.RouterFile, 1) < 0) { 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; return -1;
} }
} else { } else {
log_fn(LOG_INFO, "Loading internal default router list.");
if (config_assign_default_dirservers() < 0) if (config_assign_default_dirservers() < 0)
return -1; return -1;
} }
if (get_data_directory(&options)) { if (get_data_directory(&options)) {
char *s; 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); s = read_file_to_str(filename,0);
if (s) { if (s) {
log_fn(LOG_INFO, "Loading cached directory from %s", filename); log_fn(LOG_INFO, "Loading cached directory from %s", filename);
if (router_load_routerlist_from_string(s, 0) < 0) { 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; return 0;