diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-01-11 14:02:59 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-16 15:03:44 -0500 |
commit | 9c29369a04cdf47bd882579331577d82305bf785 (patch) | |
tree | 4a9752c89feb50c9fced1d18fdb4bbf24e3d9b72 /src/or/connection_edge.c | |
parent | cc02823d7f6acbc3fa8ea87e5646921100796f10 (diff) | |
download | tor-9c29369a04cdf47bd882579331577d82305bf785.tar.gz tor-9c29369a04cdf47bd882579331577d82305bf785.zip |
Convert instances of tor_malloc+tor_snprintf into tor_asprintf
These were found by looking for tor_snprintf() instances that were
preceeded closely by tor_malloc(), though I probably converted some
more snprintfs as well.
(In every case, make sure that the length variable (if any) is
removed, renamed, or lowered, so that anything else that might have
assumed a longer buffer doesn't exist.)
Diffstat (limited to 'src/or/connection_edge.c')
-rw-r--r-- | src/or/connection_edge.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 7de627d729..dcb9cae423 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -909,13 +909,10 @@ addressmap_ent_remove(const char *address, addressmap_entry_t *ent) static void clear_trackexithost_mappings(const char *exitname) { - char *suffix; - size_t suffix_len; + char *suffix = NULL; if (!addressmap || !exitname) return; - suffix_len = strlen(exitname) + 16; - suffix = tor_malloc(suffix_len); - tor_snprintf(suffix, suffix_len, ".%s.exit", exitname); + tor_asprintf(&suffix, ".%s.exit", exitname); tor_strlower(suffix); STRMAP_FOREACH_MODIFY(addressmap, address, addressmap_entry_t *, ent) { @@ -1402,9 +1399,8 @@ client_dns_set_reverse_addressmap(const char *address, const char *v, const char *exitname, int ttl) { - size_t len = strlen(address) + 16; - char *s = tor_malloc(len); - tor_snprintf(s, len, "REVERSE[%s]", address); + char *s = NULL; + tor_asprintf(&s, "REVERSE[%s]", address); client_dns_set_addressmap_impl(s, v, exitname, ttl); tor_free(s); } @@ -1688,21 +1684,18 @@ addressmap_get_mappings(smartlist_t *sl, time_t min_expires, addressmap_ent_remove(key, val); continue; } else if (val->new_address) { - size_t len = strlen(key)+strlen(val->new_address)+ISO_TIME_LEN+5; - char *line = tor_malloc(len); if (want_expiry) { if (val->expires < 3 || val->expires == TIME_MAX) - tor_snprintf(line, len, "%s %s NEVER", key, val->new_address); + smartlist_add_asprintf(sl, "%s %s NEVER", key, val->new_address); else { char time[ISO_TIME_LEN+1]; format_iso_time(time, val->expires); - tor_snprintf(line, len, "%s %s \"%s\"", key, val->new_address, + smartlist_add_asprintf(sl, "%s %s \"%s\"", key, val->new_address, time); } } else { - tor_snprintf(line, len, "%s %s", key, val->new_address); + smartlist_add_asprintf(sl, "%s %s", key, val->new_address); } - smartlist_add(sl, line); } } iter = strmap_iter_next(addressmap,iter); |