summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/or/dns.c7
-rw-r--r--src/or/eventdns.c13
3 files changed, 15 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 743970c929..0e35207cc3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -131,6 +131,8 @@ Changes in version 0.2.0.1-alpha - 2007-??-??
try to use \ consistently on Windows and / consistently on Unix: it
makes the log messages nicer.
- Correctly report platform name on Windows 95 OSR2 and Windows 98 SE.
+ - Read resolv.conf files correctly on platforms where read() returns
+ partial results on small file reads.
o Minor bugfixes (directory):
- Correctly enforce that elements of directory objects do not appear
diff --git a/src/or/dns.c b/src/or/dns.c
index 7cf6f9fad4..588389ae18 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -1054,6 +1054,7 @@ configure_nameservers(int force)
or_options_t *options;
const char *conf_fname;
struct stat st;
+ int r;
options = get_options();
conf_fname = options->ServerDNSResolvConfFile;
#ifndef MS_WINDOWS
@@ -1078,9 +1079,9 @@ configure_nameservers(int force)
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) {
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index fb267babc7..48db73d7ce 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -2691,7 +2691,7 @@ resolv_conf_parse_line(char *const start, int flags) {
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;
@@ -2715,10 +2715,15 @@ evdns_resolv_conf_parse(int flags, const char *const filename) {
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 (;;) {