ext/eventdns.c multiple replacements of snprintf() with tor_snprintf() which always null terminates and returns -1 if result is truncated.

This commit is contained in:
Jeremy 2015-12-01 12:29:08 -05:00
parent fcc6541fde
commit 86a5305d46

View File

@ -388,7 +388,7 @@ debug_ntoa(u32 address)
{
static char buf[32];
u32 a = ntohl(address);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d",
tor_snprintf(buf, sizeof(buf), "%d.%d.%d.%d",
(int)(u8)((a>>24)&0xff),
(int)(u8)((a>>16)&0xff),
(int)(u8)((a>>8 )&0xff),
@ -436,12 +436,7 @@ evdns_log(int warn, const char *fmt, ...)
if (!evdns_log_fn)
return;
va_start(args,fmt);
#ifdef _WIN32
_vsnprintf(buf, sizeof(buf), fmt, args);
#else
vsnprintf(buf, sizeof(buf), fmt, args);
#endif
buf[sizeof(buf)-1] = '\0';
tor_vsnprintf(buf, sizeof(buf), fmt, args);
evdns_log_fn(warn, buf);
va_end(args);
}
@ -762,7 +757,7 @@ reply_handle(struct evdns_request *const req, u16 flags, u32 ttl, struct reply *
/* we regard these errors as marking a bad nameserver */
if (req->reissue_count < global_max_reissues) {
char msg[64];
snprintf(msg, sizeof(msg), "Bad response %d (%s)",
tor_snprintf(msg, sizeof(msg), "Bad response %d (%s)",
error, evdns_err_to_string(error));
nameserver_failed(req->ns, msg);
if (!request_reissue(req)) return;
@ -1705,7 +1700,7 @@ evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_a
assert(!(in && inaddr_name));
if (in) {
a = ntohl(in->s_addr);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
tor_snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
(int)(u8)((a )&0xff),
(int)(u8)((a>>8 )&0xff),
(int)(u8)((a>>16)&0xff),
@ -2638,7 +2633,7 @@ int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_ty
u32 a;
assert(in);
a = ntohl(in->s_addr);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
tor_snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
(int)(u8)((a )&0xff),
(int)(u8)((a>>8 )&0xff),
(int)(u8)((a>>16)&0xff),