From 5be24333aec311d776e7d6c5fde9e74fcf04217d Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Mon, 28 May 2007 21:09:00 +0000 Subject: [PATCH] solaris may return short reads on resolve.conf; fix from tor cvs via Nick Mathewson svn:r358 --- evdns.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/evdns.c b/evdns.c index d76be335..f66239bb 100644 --- a/evdns.c +++ b/evdns.c @@ -2649,7 +2649,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; @@ -2673,10 +2673,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; - } - resolv[st.st_size] = 0; // we malloced an extra byte + 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); + } + if (r < 0) { err = 5; goto out2; } + resolv[n] = 0; // we malloced an extra byte; this should be fine. start = (char *) resolv; for (;;) { -- 2.40.0