From: Wouter Wijngaards Date: Fri, 24 Sep 2010 12:12:16 +0000 (+0000) Subject: * bugfix: tcp read could fail on single octet recv. X-Git-Tag: release-1.6.7~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c62a6e12e047cc49cd490bd35cd7cf7d4557cf3a;p=thirdparty%2Fldns.git * bugfix: tcp read could fail on single octet recv. --- diff --git a/Changelog b/Changelog index fbc41872..43e01373 100644 --- a/Changelog +++ b/Changelog @@ -11,6 +11,7 @@ names changed to RFC names and aliases for compatibility added. * bugfix: don't print final dot if the domain is relative. * bugfix: resolver search continue when packet rcode != NOERROR. + * bugfix: tcp read could fail on single octet recv. 1.6.6 * Fix ldns_rr_clone to copy question rrs properly. diff --git a/net.c b/net.c index e374e67c..1b067545 100644 --- a/net.c +++ b/net.c @@ -532,12 +532,14 @@ ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout) LDNS_FREE(wire); return NULL; } - bytes = recv(sockfd, (void*)wire, 2, 0); - if (bytes == -1 || bytes == 0) { + rc = recv(sockfd, (void*) (wire + bytes), + (size_t) (2 - bytes), 0); + if (rc == -1 || rc == 0) { *size = 0; LDNS_FREE(wire); return NULL; } + bytes += rc; } wire_size = ldns_read_uint16(wire); @@ -580,12 +582,14 @@ ldns_tcp_read_wire(int sockfd, size_t *size) } while (bytes < 2) { - bytes = recv(sockfd, (void*)wire, 2, 0); - if (bytes == -1 || bytes == 0) { + rc = recv(sockfd, (void*) (wire + bytes), + (size_t) (2 - bytes), 0); + if (rc == -1 || rc == 0) { *size = 0; LDNS_FREE(wire); return NULL; } + bytes += rc; } wire_size = ldns_read_uint16(wire);