Browse Source

Fix bug reported by peter palfrader: an empty address is unresolvable, but not an occasion for an assertion failure in a dnsworker.

svn:r2015
Nick Mathewson 21 years ago
parent
commit
d5e275ddf4
2 changed files with 5 additions and 3 deletions
  1. 4 1
      src/common/util.c
  2. 1 2
      src/or/dns.c

+ 4 - 1
src/common/util.c

@@ -1709,7 +1709,10 @@ int tor_lookup_hostname(const char *name, uint32_t *addr)
   struct in_addr iaddr;
   struct hostent *ent;
   tor_assert(addr);
-  if (tor_inet_aton(name, &iaddr)) {
+  if (!*name) {
+    /* Empty address is an error. */
+    return -1;
+  } if (tor_inet_aton(name, &iaddr)) {
     /* It's an IP. */
     memcpy(addr, &iaddr.s_addr, 4);
     return 0;

+ 1 - 2
src/or/dns.c

@@ -648,9 +648,8 @@ static int dnsworker_main(void *data) {
       log_fn(LOG_INFO,"dnsworker exiting because tor process died.");
       spawn_exit();
     }
-    tor_assert(address_len > 0);
 
-    if(read_all(fd, address, address_len, 1) != address_len) {
+    if(address_len && read_all(fd, address, address_len, 1) != address_len) {
       log_fn(LOG_ERR,"read hostname failed. Child exiting.");
       spawn_exit();
     }