]> granicus.if.org Git - libevent/commitdiff
Don't truncate hosts file path on Windows.
authorVilmos Nebehaj <v.nebehaj@gmail.com>
Fri, 21 Mar 2014 13:38:11 +0000 (14:38 +0100)
committerVilmos Nebehaj <v.nebehaj@gmail.com>
Fri, 21 Mar 2014 13:38:11 +0000 (14:38 +0100)
Since evutil_snprintf() (actually evutil_vsnprintf() called by it) will
make sure the buffer is null-terminated by placing a null byte at
len_out - 1, we need to pass the full length of the buffer; otherwise
the path will end in "\\host" instead of "\\hosts".

evdns.c

diff --git a/evdns.c b/evdns.c
index a143074d4aaa6dd6b4452d7d478ddf541a601c94..a1d8c95a359d119c7eab8a6cee7399a2b64e1349 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -3555,8 +3555,8 @@ evdns_get_default_hosts_filename(void)
 
        if (! SHGetSpecialFolderPathA(NULL, path, CSIDL_SYSTEM, 0))
                return NULL;
-       len_out = strlen(path)+strlen(hostfile);
-       path_out = mm_malloc(len_out+1);
+       len_out = strlen(path)+strlen(hostfile)+1;
+       path_out = mm_malloc(len_out);
        evutil_snprintf(path_out, len_out, "%s%s", path, hostfile);
        return path_out;
 #else