[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10243: Backport 10237: use the same logic as in read_all when readi (in tor/branches/tor-0_1_2-patches: . src/or)



Author: nickm
Date: 2007-05-21 21:39:31 -0400 (Mon, 21 May 2007)
New Revision: 10243

Modified:
   tor/branches/tor-0_1_2-patches/
   tor/branches/tor-0_1_2-patches/ChangeLog
   tor/branches/tor-0_1_2-patches/src/or/dns.c
   tor/branches/tor-0_1_2-patches/src/or/eventdns.c
Log:
 r12840@catbus:  nickm | 2007-05-21 21:39:23 -0400
 Backport 10237: use the same logic as in read_all when reading resolv.conf.  Maybe this fixes bug 433.



Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
 svk:merge ticket from /tor/012 [r12840] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog	2007-05-22 01:20:23 UTC (rev 10242)
+++ tor/branches/tor-0_1_2-patches/ChangeLog	2007-05-22 01:39:31 UTC (rev 10243)
@@ -24,6 +24,8 @@
       network-statuses.
     - Correctly back-off from requesting router descriptors that we are
       having a hard time downloading.
+    - Read resolv.conf files correctly on platforms where read() returns
+      partial results on small file reads.
 
   o Minor features:
     - When routers publish SVN revisions in their router descriptors,

Modified: tor/branches/tor-0_1_2-patches/src/or/dns.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/dns.c	2007-05-22 01:20:23 UTC (rev 10242)
+++ tor/branches/tor-0_1_2-patches/src/or/dns.c	2007-05-22 01:39:31 UTC (rev 10243)
@@ -1519,6 +1519,7 @@
   or_options_t *options;
   const char *conf_fname;
   struct stat st;
+  int r;
   options = get_options();
   conf_fname = options->ServerDNSResolvConfFile;
 #ifndef MS_WINDOWS
@@ -1543,9 +1544,9 @@
       evdns_clear_nameservers_and_suspend();
     }
     log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname);
-    if (evdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname)) {
-      log_warn(LD_EXIT, "Unable to parse '%s', or no nameservers in '%s'",
-               conf_fname, conf_fname);
+    if ((r = evdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname))) {
+      log_warn(LD_EXIT, "Unable to parse '%s', or no nameservers in '%s' (%d)",
+               conf_fname, conf_fname, r);
       return -1;
     }
     if (evdns_count_nameservers() == 0) {

Modified: tor/branches/tor-0_1_2-patches/src/or/eventdns.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/eventdns.c	2007-05-22 01:20:23 UTC (rev 10242)
+++ tor/branches/tor-0_1_2-patches/src/or/eventdns.c	2007-05-22 01:39:31 UTC (rev 10243)
@@ -2683,7 +2683,7 @@
 int
 evdns_resolv_conf_parse(int flags, const char *const filename) {
 	struct stat st;
-	int fd;
+	int fd, n, r;
 	u8 *resolv;
 	char *start;
 	int err = 0;
@@ -2707,10 +2707,15 @@
 	resolv = (u8 *) malloc((size_t)st.st_size + 1);
 	if (!resolv) { err = 4; goto out1; }
 
-	if (read(fd, resolv, (size_t)st.st_size) != st.st_size) {
-		err = 5; goto out2;
+    n = 0;
+	while ((r = read(fd, resolv+n, (size_t)st.st_size-n)) > 0) {
+		n += r;
+		if (n == st.st_size)
+			break;
+		assert(n < st.st_size);
 	}
-	resolv[st.st_size] = 0;	 // we malloced an extra byte
+	if (r < 0) { err = 5; goto out2; }
+	resolv[n] = 0;	 // we malloced an extra byte; this should be fine.
 
 	start = (char *) resolv;
 	for (;;) {