]> granicus.if.org Git - libevent/commitdiff
Fix the code that allowed DNS options to not end with :
authorNick Mathewson <nickm@torproject.org>
Tue, 29 Dec 2009 21:03:30 +0000 (16:03 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 29 Dec 2009 21:03:30 +0000 (16:03 -0500)
We tried to fix this in 0.2.0.3-alpha, but our fix was buggy.

evdns.c

diff --git a/evdns.c b/evdns.c
index 1eb8f9c4fec60f2fa085fcf80d760da219a2385e..b91f420941a69d89501c7a5cf31c032481c84e68 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -3130,8 +3130,11 @@ strtotimeval(const char *const str, struct timeval *out)
        char *endptr;
        d = strtod(str, &endptr);
        if (*endptr) return -1;
+       if (d < 0) return -1;
        out->tv_sec = (int) d;
        out->tv_usec = (int) ((d - (int) d)*1000000);
+       if (out->tv_sec == 0 && out->tv_usec < 1000) /* less than 1 msec */
+               return -1;
        return 0;
 }
 
@@ -3200,10 +3203,13 @@ str_matches_option(const char *s1, const char *optionname)
         * s1, or 'option:randomjunk'.  The latter form is to implement the
         * resolv.conf parser. */
        size_t optlen = strlen(optionname);
-       if (strlen(s1) == optlen)
-               return !strncmp(s1, optionname, optlen-1);
-       else
+       size_t slen = strlen(s1);
+       if (slen == optlen || slen == optlen - 1)
+               return !strncmp(s1, optionname, slen);
+       else if (slen > optlen)
                return !strncmp(s1, optionname, optlen);
+       else
+               return 0;
 }
 
 static int