diff options
-rw-r--r-- | src/common/log.c | 49 | ||||
-rw-r--r-- | src/common/tortls.c | 2 | ||||
-rw-r--r-- | src/common/util.c | 4 | ||||
-rw-r--r-- | src/or/circuitbuild.c | 10 | ||||
-rw-r--r-- | src/or/connection_edge.c | 4 | ||||
-rw-r--r-- | src/or/directory.c | 18 | ||||
-rw-r--r-- | src/or/dirserv.c | 8 | ||||
-rw-r--r-- | src/or/main.c | 4 | ||||
-rw-r--r-- | src/or/rendservice.c | 2 | ||||
-rw-r--r-- | src/or/rephist.c | 12 | ||||
-rw-r--r-- | src/or/router.c | 44 | ||||
-rw-r--r-- | src/or/routerlist.c | 6 | ||||
-rw-r--r-- | src/or/routerparse.c | 2 | ||||
-rw-r--r-- | src/or/test.c | 4 |
14 files changed, 82 insertions, 87 deletions
diff --git a/src/common/log.c b/src/common/log.c index 06da75839d..7073df18ad 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -16,12 +16,6 @@ #include "./util.h" #include "./log.h" - -#ifdef MS_WINDOWS -#define vsnprintf _vsnprintf -#define snprintf _snprintf -#endif - #define TRUNCATED_STR "[...truncated]" #define TRUNCATED_STR_LEN 14 @@ -65,19 +59,19 @@ _log_prefix(char *buf, size_t buf_len, int severity) time_t t; struct timeval now; size_t n; + int r; tor_gettimeofday(&now); t = (time_t)now.tv_sec; n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t)); - n += snprintf(buf+n, buf_len-n, + r = tor_snprintf(buf+n, buf_len-n, ".%.3ld [%s] ", (long)now.tv_usec / 1000, sev_to_string(severity)); - if(n > buf_len) - n = buf_len-1; /* the *nprintf funcs return how many bytes they - * _would_ print, if the output is truncated. - * Subtract one because the count doesn't include the \0 */ - return n; + if (r<0) + return buf_len-1; + else + return n+r; } /** If lf refers to an actual file that we have just opened, and the file @@ -99,12 +93,9 @@ static void log_tor_version(logfile_t *lf, int reset) /* We are resetting, but we aren't at the start of the file; no * need to log again. */ return; - n = _log_prefix(buf, 250, LOG_NOTICE); - n += snprintf(buf+n, 250-n, "Tor %s opening %slog file.\n", VERSION, - is_new?"new ":""); - if (n>250) - n = 250; - buf[n+1]='\0'; + n = _log_prefix(buf, sizeof(buf), LOG_NOTICE); + tor_snprintf(buf+n, sizeof(buf)-n, + "Tor %s opening %slog file.\n", VERSION, is_new?"new ":""); fputs(buf, lf->file); } @@ -118,6 +109,7 @@ static INLINE char *format_msg(char *buf, size_t buf_len, const char *format, va_list ap) { size_t n; + int r; char *end_of_prefix; buf_len -= 2; /* subtract 2 characters so we have room for \n\0 */ @@ -125,15 +117,18 @@ static INLINE char *format_msg(char *buf, size_t buf_len, end_of_prefix = buf+n; if (funcname) { - n += snprintf(buf+n, buf_len-n, "%s(): ", funcname); - if(n > buf_len) - n = buf_len-1; + r = tor_snprintf(buf+n, buf_len-n, "%s(): ", funcname); + if (r<0) + n = strlen(buf); + else + n += r; } - - n += vsnprintf(buf+n,buf_len-n,format,ap); - if(n > buf_len) { - n = buf_len-1; - strcpy(buf+n-TRUNCATED_STR_LEN, TRUNCATED_STR); + + n += tor_vsnprintf(buf+n,buf_len-n,format,ap); + if(n < 0) { + n = buf_len-2; + strlcpy(buf+buf_len-TRUNCATED_STR_LEN-1, TRUNCATED_STR, + buf_len-(buf_len-TRUNCATED_STR_LEN-1)); } buf[n]='\n'; buf[n+1]='\0'; @@ -142,7 +137,7 @@ static INLINE char *format_msg(char *buf, size_t buf_len, /** Helper: sends a message to the appropriate logfiles, at loglevel * <b>severity</b>. If provided, <b>funcname</b> is prepended to the - * message. The actual message is derived as from vsnprintf(format,ap). + * message. The actual message is derived as from tor_snprintf(format,ap). */ static void logv(int severity, const char *funcname, const char *format, va_list ap) diff --git a/src/common/tortls.c b/src/common/tortls.c index 84366176e6..03b55c0191 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -299,7 +299,7 @@ tor_tls_context_new(crypto_pk_env_t *identity, SSL_CTX **ctx; if (!nickname) nickname = "null"; - snprintf(nn2, sizeof(nn2), "%s <identity>", nickname); + tor_snprintf(nn2, sizeof(nn2), "%s <identity>", nickname); tor_tls_init(); diff --git a/src/common/util.c b/src/common/util.c index 2d09a32942..09a86ebdbc 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1773,7 +1773,7 @@ char *expand_filename(const char *filename) * Round up to 16 in case we can't do math. */ len = strlen(home)+strlen(filename)+16; result = tor_malloc(len); - snprintf(result,len,"%s/%s",home,filename+2); + tor_snprintf(result,len,"%s/%s",home,filename+2); return result; } else { return tor_strdup(filename); @@ -1847,7 +1847,7 @@ get_uname(void) #ifdef HAVE_UNAME if (uname(&u) != -1) { /* (linux says 0 is success, solaris says 1 is success) */ - snprintf(uname_result, 255, "%s %s %s", + tor_snprintf(uname_result, 255, "%s %s %s", u.sysname, u.nodename, u.machine); uname_result[255] = '\0'; } else diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index f9a369e59c..91213b72d9 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -76,20 +76,20 @@ void circuit_log_path(int severity, circuit_t *circ) { tor_assert(CIRCUIT_IS_ORIGIN(circ)); tor_assert(circ->cpath); - snprintf(s, sizeof(buf)-1, "circ (length %d, exit %s): ", + tor_snprintf(s, sizeof(buf)-1, "circ (length %d, exit %s): ", circ->build_state->desired_path_len, circ->build_state->chosen_exit_name); hop=circ->cpath; do { s = buf + strlen(buf); router = router_get_by_digest(hop->identity_digest); if(router) { - snprintf(s, sizeof(buf) - (s - buf), "%s(%s) ", + tor_snprintf(s, sizeof(buf) - (s - buf), "%s(%s) ", router->nickname, states[hop->state]); } else { if(circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) { - snprintf(s, sizeof(buf) - (s - buf), "(rendjoin hop)"); + tor_snprintf(s, sizeof(buf) - (s - buf), "(rendjoin hop)"); } else { - snprintf(s, sizeof(buf) - (s - buf), "UNKNOWN "); + tor_snprintf(s, sizeof(buf) - (s - buf), "UNKNOWN "); } } hop=hop->next; @@ -1105,7 +1105,7 @@ static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state) for(i=0; i < smartlist_len(rl->routers); i++) { r = smartlist_get(rl->routers, i); - snprintf(buf, sizeof(buf), "%d", r->or_port); + tor_snprintf(buf, sizeof(buf), "%d", r->or_port); if(!smartlist_string_isin(options.FirewallPorts, buf)) smartlist_add(excluded, r); } diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 6ff223bce4..ed2b7f15e6 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -502,12 +502,12 @@ int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) in.s_addr = htonl(client_dns_lookup_entry(ap_conn->socks_request->address)); string_addr = in.s_addr ? inet_ntoa(in) : NULL; - snprintf(payload,RELAY_PAYLOAD_SIZE, + tor_snprintf(payload,RELAY_PAYLOAD_SIZE, "%s:%d", string_addr ? string_addr : ap_conn->socks_request->address, ap_conn->socks_request->port); } else { - snprintf(payload,RELAY_PAYLOAD_SIZE, + tor_snprintf(payload,RELAY_PAYLOAD_SIZE, ":%d", ap_conn->socks_request->port); } payload_len = strlen(payload)+1; diff --git a/src/or/directory.c b/src/or/directory.c index 45f69a3c3d..0418b7b7e7 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -131,7 +131,7 @@ directory_post_to_dirservers(uint8_t purpose, const char *payload, * descriptor -- those use Tor. */ if (options.FascistFirewall && purpose == DIR_PURPOSE_UPLOAD_DIR && !options.HttpProxy) { - snprintf(buf,sizeof(buf),"%d",ds->dir_port); + tor_snprintf(buf,sizeof(buf),"%d",ds->dir_port); if (!smartlist_string_isin(options.FirewallPorts, buf)) continue; } @@ -325,10 +325,10 @@ directory_send_command(connection_t *conn, const char *platform, if(conn->port == 80) { strlcpy(hoststring, conn->address, sizeof(hoststring)); } else { - snprintf(hoststring, sizeof(hoststring),"%s:%d",conn->address, conn->port); + tor_snprintf(hoststring, sizeof(hoststring),"%s:%d",conn->address, conn->port); } if(options.HttpProxy) { - snprintf(proxystring, sizeof(proxystring),"http://%s", hoststring); + tor_snprintf(proxystring, sizeof(proxystring),"http://%s", hoststring); } else { proxystring[0] = 0; } @@ -361,7 +361,7 @@ directory_send_command(connection_t *conn, const char *platform, conn->rend_query[payload_len] = 0; httpcommand = "GET"; - snprintf(url, sizeof(url), "%s/rendezvous/%s", use_newer ? "/tor" : "", payload); + tor_snprintf(url, sizeof(url), "%s/rendezvous/%s", use_newer ? "/tor" : "", payload); /* XXX We're using payload here to mean something other than * payload of the http post. This is probably bad, and should @@ -373,11 +373,11 @@ directory_send_command(connection_t *conn, const char *platform, case DIR_PURPOSE_UPLOAD_RENDDESC: tor_assert(payload); httpcommand = "POST"; - snprintf(url, sizeof(url), "%s/rendezvous/publish", use_newer ? "/tor" : ""); + tor_snprintf(url, sizeof(url), "%s/rendezvous/publish", use_newer ? "/tor" : ""); break; } - snprintf(tmp, sizeof(tmp), "%s %s%s HTTP/1.0\r\nContent-Length: %lu\r\nHost: %s\r\n\r\n", + tor_snprintf(tmp, sizeof(tmp), "%s %s%s HTTP/1.0\r\nContent-Length: %lu\r\nHost: %s\r\n\r\n", httpcommand, proxystring, url, @@ -758,7 +758,7 @@ directory_handle_command_get(connection_t *conn, char *headers, log_fn(LOG_DEBUG,"Dumping %sdirectory to client.", deflated?"deflated ":""); format_rfc1123_time(date, time(NULL)); - snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: text/plain\r\nContent-Encoding: %s\r\n\r\n", + tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: text/plain\r\nContent-Encoding: %s\r\n\r\n", date, (int)dlen, deflated?"deflate":"identity"); @@ -781,7 +781,7 @@ directory_handle_command_get(connection_t *conn, char *headers, } format_rfc1123_time(date, time(NULL)); - snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: text/plain\r\n\r\n", + tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: text/plain\r\n\r\n", date, (int)dlen); connection_write_to_buf(tmp, strlen(tmp), conn); @@ -807,7 +807,7 @@ directory_handle_command_get(connection_t *conn, char *headers, switch(rend_cache_lookup_desc(url+strlen("/tor/rendezvous/"), &descp, &desc_len)) { case 1: /* valid */ format_rfc1123_time(date, time(NULL)); - snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n", + tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n", date, (int)desc_len); /* can't include descp here, because it's got nuls */ connection_write_to_buf(tmp, strlen(tmp), conn); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index f108178464..06d1a5a81d 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -616,7 +616,7 @@ dirserv_dump_directory_to_string(char *s, size_t maxlen, dirserv_remove_old_servers(ROUTER_MAX_AGE); published_on = time(NULL); format_iso_time(published, published_on); - snprintf(s, maxlen, + tor_snprintf(s, maxlen, "signed-directory\n" "published %s\n" "recommended-software %s\n" @@ -711,7 +711,7 @@ void dirserv_set_cached_directory(const char *directory, time_t when) } cached_directory_published = when; if(get_data_directory(&options)) { - snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options)); + tor_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."); } @@ -783,7 +783,7 @@ static int dirserv_regenerate_directory(void) } tor_free(new_directory); if(get_data_directory(&options)) { - snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options)); + tor_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."); } @@ -833,7 +833,7 @@ static int generate_runningrouters(crypto_pk_env_t *private_key) #endif published_on = time(NULL); format_iso_time(published, published_on); - snprintf(s, len, "network-status\n" + tor_snprintf(s, len, "network-status\n" "published %s\n" "router-status %s\n" "opt dir-signing-key %s\n" diff --git a/src/or/main.c b/src/or/main.c index 3adb12062f..b665b506ac 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -757,7 +757,7 @@ static int do_hup(void) { } if(authdir_mode()) { /* reload the approved-routers file */ - snprintf(keydir,sizeof(keydir),"%s/approved-routers", get_data_directory(&options)); + tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", get_data_directory(&options)); log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir); if(dirserv_parse_fingerprint_file(keydir) < 0) { log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list."); @@ -772,7 +772,7 @@ static int do_hup(void) { dnsworkers_rotate(); /* Rebuild fresh descriptor as needed. */ router_rebuild_descriptor(); - snprintf(keydir,sizeof(keydir),"%s/router.desc", get_data_directory(&options)); + tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", get_data_directory(&options)); log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir); if (write_str_to_file(keydir, router_get_my_descriptor(), 0)) { return -1; diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 34711c8e54..9ca1f8a390 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -309,7 +309,7 @@ int rend_service_load_keys(void) log_fn(LOG_WARN, "Directory name too long: '%s'", s->directory); return -1; } - snprintf(buf, sizeof(buf),"%s.onion\n", s->service_id); + tor_snprintf(buf, sizeof(buf),"%s.onion\n", s->service_id); if (write_str_to_file(fname,buf,0)<0) return -1; } diff --git a/src/or/rephist.c b/src/or/rephist.c index 8c6b6cf559..9a99442cd2 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -279,8 +279,8 @@ void rep_hist_dump_stats(time_t now, int severity) name2 = "(unknown)"; link_history = (link_history_t*) link_history_p; -/* XXX009 snprintf can return -1 for error also. need to detect. */ - len += snprintf(buffer+len, 2048-len, "%s(%ld/%ld); ", name2, +/* XXX009 tor_snprintf can return -1 for error also. need to detect. */ + len += tor_snprintf(buffer+len, 2048-len, "%s(%ld/%ld); ", name2, link_history->n_extend_ok, link_history->n_extend_ok+link_history->n_extend_fail); if (len >= 2048) { @@ -307,7 +307,7 @@ void write_rep_history(const char *filename) const char *name1; tmpfile = tor_malloc(strlen(filename)+5); - snprintf(tmpfile, strlen(filename)+5, "%s_tmp", filename); + tor_snprintf(tmpfile, strlen(filename)+5, "%s_tmp", filename); f = fopen(tmpfile, "w"); if (!f) goto done; @@ -527,7 +527,7 @@ char *rep_hist_get_bandwidth_lines(void) for (r=0;r<2;++r) { b = r?read_array:write_array; format_iso_time(t, b->next_period-NUM_SECS_BW_SUM_INTERVAL); - snprintf(cp, len-(cp-buf), "opt %s %s (%d s) ", r?"read-history ":"write-history", t, + tor_snprintf(cp, len-(cp-buf), "opt %s %s (%d s) ", r?"read-history ":"write-history", t, NUM_SECS_BW_SUM_INTERVAL); cp += strlen(cp); @@ -542,9 +542,9 @@ char *rep_hist_get_bandwidth_lines(void) for (n=0; n<b->num_maxes_set; ++n,++i) { while (i >= NUM_TOTALS) i -= NUM_TOTALS; if (n==(b->num_maxes_set-1)) - snprintf(cp, len-(cp-buf), "%d", b->totals[i]); + tor_snprintf(cp, len-(cp-buf), "%d", b->totals[i]); else - snprintf(cp, len-(cp-buf), "%d,", b->totals[i]); + tor_snprintf(cp, len-(cp-buf), "%d,", b->totals[i]); cp += strlen(cp); } strlcat(cp, "\n", len-(cp-buf)); diff --git a/src/or/router.c b/src/or/router.c index 799c7b3002..c0d6947e99 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -101,9 +101,9 @@ void rotate_onion_key(void) char fname[512]; char fname_prev[512]; crypto_pk_env_t *prkey; - snprintf(fname,sizeof(fname), + tor_snprintf(fname,sizeof(fname), "%s/keys/secret_onion_key",get_data_directory(&options)); - snprintf(fname_prev,sizeof(fname_prev), + tor_snprintf(fname_prev,sizeof(fname_prev), "%s/keys/secret_onion_key.old",get_data_directory(&options)); if (!(prkey = crypto_new_pk_env())) { log(LOG_ERR, "Error creating crypto environment."); @@ -264,27 +264,27 @@ int init_keys(void) { return -1; } /* Check the key directory. */ - snprintf(keydir,sizeof(keydir),"%s/keys", datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/keys", datadir); if (check_private_dir(keydir, 1)) { return -1; } cp = keydir + strlen(keydir); /* End of string. */ /* 1. Read identity key. Make it if none is found. */ - snprintf(keydir,sizeof(keydir),"%s/keys/identity.key",datadir); - snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_id_key",datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/keys/identity.key",datadir); + tor_snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_id_key",datadir); log_fn(LOG_INFO,"Reading/making identity key %s...",keydir2); prkey = init_key_from_file_name_changed(keydir,keydir2); if (!prkey) return -1; set_identity_key(prkey); /* 2. Read onion key. Make it if none is found. */ - snprintf(keydir,sizeof(keydir),"%s/keys/onion.key",datadir); - snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_onion_key",datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/keys/onion.key",datadir); + tor_snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_onion_key",datadir); log_fn(LOG_INFO,"Reading/making onion key %s...",keydir2); prkey = init_key_from_file_name_changed(keydir,keydir2); if (!prkey) return -1; set_onion_key(prkey); - snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key.old",datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/keys/secret_onion_key.old",datadir); if (file_status(keydir) == FN_FILE) { prkey = init_key_from_file(keydir); if (prkey) @@ -316,13 +316,13 @@ int init_keys(void) { } } - snprintf(keydir,sizeof(keydir),"%s/router.desc", datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", datadir); log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir); if (write_str_to_file(keydir, mydesc,0)) { return -1; } /* 5. Dump fingerprint to 'fingerprint' */ - snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir); log_fn(LOG_INFO,"Dumping fingerprint to %s...",keydir); tor_assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN); strlcpy(fingerprint, options.Nickname, sizeof(fingerprint)); @@ -338,7 +338,7 @@ int init_keys(void) { if(!authdir_mode()) return 0; /* 6. [authdirserver only] load approved-routers file */ - snprintf(keydir,sizeof(keydir),"%s/approved-routers", datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", datadir); log_fn(LOG_INFO,"Loading approved fingerprints from %s...",keydir); if(dirserv_parse_fingerprint_file(keydir) < 0) { log_fn(LOG_ERR, "Error loading fingerprints"); @@ -350,7 +350,7 @@ int init_keys(void) { add_trusted_dir_server(options.Address, (uint16_t)options.DirPort, digest); } /* 7. [authdirserver only] load old directory, if it's there */ - snprintf(keydir,sizeof(keydir),"%s/cached-directory", datadir); + tor_snprintf(keydir,sizeof(keydir),"%s/cached-directory", datadir); log_fn(LOG_INFO,"Loading cached directory from %s...",keydir); cp = read_file_to_str(keydir,0); if(!cp) { @@ -568,7 +568,7 @@ int router_rebuild_descriptor(void) { */ void get_platform_str(char *platform, size_t len) { - snprintf(platform, len-1, "Tor %s on %s", + tor_snprintf(platform, len-1, "Tor %s on %s", VERSION, get_uname()); platform[len-1] = '\0'; return; @@ -643,14 +643,14 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, char *s = smartlist_join_strings(router->declared_family, " ", 0); size_t n = strlen(s) + strlen("opt family ") + 2; /* 1 for \n, 1 for \0. */ family_line = tor_malloc(n); - snprintf(family_line, n, "opt family %s\n", s); + tor_snprintf(family_line, n, "opt family %s\n", s); tor_free(s); } else { family_line = tor_strdup(""); } /* Generate the easy portion of the router descriptor. */ - result = snprintf(s, maxlen, + result = tor_snprintf(s, maxlen, "router %s %s %d %d %d\n" "platform %s\n" "published %s\n" @@ -679,14 +679,14 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, tor_free(bandwidth_usage); if(result < 0 || (size_t)result >= maxlen) { - /* apparently different glibcs do different things on snprintf error.. so check both */ + /* apparently different glibcs do different things on tor_snprintf error.. so check both */ return -1; } /* From now on, we use 'written' to remember the current length of 's'. */ written = result; if (options.ContactInfo && strlen(options.ContactInfo)) { - result = snprintf(s+written,maxlen-written, "opt contact %s\n", + result = tor_snprintf(s+written,maxlen-written, "opt contact %s\n", options.ContactInfo); if (result<0 || result+written > maxlen) return -1; @@ -697,18 +697,18 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, for(tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) { in.s_addr = htonl(tmpe->addr); /* Write: "accept 1.2.3.4" */ - result = snprintf(s+written, maxlen-written, "%s %s", + result = tor_snprintf(s+written, maxlen-written, "%s %s", tmpe->policy_type == EXIT_POLICY_ACCEPT ? "accept" : "reject", tmpe->msk == 0 ? "*" : inet_ntoa(in)); if(result < 0 || result+written > maxlen) { - /* apparently different glibcs do different things on snprintf error.. so check both */ + /* apparently different glibcs do different things on tor_snprintf error.. so check both */ return -1; } written += result; if (tmpe->msk != 0xFFFFFFFFu && tmpe->msk != 0) { /* Write "/255.255.0.0" */ in.s_addr = htonl(tmpe->msk); - result = snprintf(s+written, maxlen-written, "/%s", inet_ntoa(in)); + result = tor_snprintf(s+written, maxlen-written, "/%s", inet_ntoa(in)); if (result<0 || result+written > maxlen) return -1; written += result; @@ -721,13 +721,13 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, written += 3; } else if (tmpe->prt_min == tmpe->prt_max) { /* There is only one port; write ":80". */ - result = snprintf(s+written, maxlen-written, ":%d\n", tmpe->prt_min); + result = tor_snprintf(s+written, maxlen-written, ":%d\n", tmpe->prt_min); if (result<0 || result+written > maxlen) return -1; written += result; } else { /* There is a range of ports; write ":79-80". */ - result = snprintf(s+written, maxlen-written, ":%d-%d\n", tmpe->prt_min, + result = tor_snprintf(s+written, maxlen-written, ":%d-%d\n", tmpe->prt_min, tmpe->prt_max); if (result<0 || result+written > maxlen) return -1; diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 9fa1453bb0..f83d7789a9 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -50,7 +50,7 @@ int router_reload_router_list(void) char filename[512]; if (get_data_directory(&options)) { char *s; - snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options)); + tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options)); s = read_file_to_str(filename,0); if (s) { tor_strstrip(s,"\r"); /* XXXX This is a bug workaround for win32. */ @@ -167,7 +167,7 @@ router_pick_directory_server_impl(int requireothers, int fascistfirewall) if(requireothers && router_is_me(router)) continue; if(fascistfirewall) { - snprintf(buf,sizeof(buf),"%d",router->dir_port); + tor_snprintf(buf,sizeof(buf),"%d",router->dir_port); if (!smartlist_string_isin(options.FirewallPorts, buf)) continue; } @@ -202,7 +202,7 @@ router_pick_trusteddirserver_impl(int requireother, int fascistfirewall) !memcmp(me->identity_digest, d->digest, DIGEST_LEN)) continue; if (fascistfirewall) { - snprintf(buf,sizeof(buf),"%d",d->dir_port); + tor_snprintf(buf,sizeof(buf),"%d",d->dir_port); if (!smartlist_string_isin(options.FirewallPorts, buf)) continue; } diff --git a/src/or/routerparse.c b/src/or/routerparse.c index bc6030b202..31f308d2ae 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1032,7 +1032,7 @@ router_parse_exit_policy(directory_token_t *tok) { newe = tor_malloc_zero(sizeof(struct exit_policy_t)); newe->string = tor_malloc(8+strlen(arg)); - snprintf(newe->string, 8+strlen(arg), "%s %s", + tor_snprintf(newe->string, 8+strlen(arg), "%s %s", (tok->tp == K_REJECT) ? "reject" : "accept", arg); newe->policy_type = (tok->tp == K_REJECT) ? EXIT_POLICY_REJECT : EXIT_POLICY_ACCEPT; diff --git a/src/or/test.c b/src/or/test.c index fecf6be2bd..0ce384ad5b 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -50,7 +50,7 @@ setup_directory() int r; if (is_setup) return; - snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid()); + tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid()); #ifdef MS_WINDOWS r = mkdir(temp_dir); #else @@ -69,7 +69,7 @@ get_fname(const char *name) { static char buf[1024]; setup_directory(); - snprintf(buf,sizeof(buf),"%s/%s",temp_dir,name); + tor_snprintf(buf,sizeof(buf),"%s/%s",temp_dir,name); return buf; } |