]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
* bugfix: tcp read could fail on single octet recv.
authorWouter Wijngaards <wouter@NLnetLabs.nl>
Fri, 24 Sep 2010 12:12:16 +0000 (12:12 +0000)
committerWouter Wijngaards <wouter@NLnetLabs.nl>
Fri, 24 Sep 2010 12:12:16 +0000 (12:12 +0000)
Changelog
net.c

index fbc41872a5d01dffd5b24294886714330d638494..43e013733c7da29442f6a9e7b3df678ab4905ded 100644 (file)
--- 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 e374e67c6f2e4c335ede11767182e5d652785649..1b067545a6ddd90fe3b9db9bd3449aea1cdca0d1 100644 (file)
--- 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);