]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use less-than instead of not-equal-to for comparison in read loops.
authorAlexander Færøy <ahf@torproject.org>
Wed, 8 Mar 2017 22:02:34 +0000 (23:02 +0100)
committerAlexander Færøy <ahf@torproject.org>
Wed, 8 Mar 2017 23:10:17 +0000 (00:10 +0100)
This patch changes a number of read loops in the util module to use
less-than comparison instead of not-equal-to comparison. We do this in
the case that we have a bug elsewhere that might cause `numread` to
become larger than `count` and thus become an infinite loop.

src/common/util.c

index 1fd3b16d7237705be31708227487bae67abc09d6..a8b44cbda7438d73ccea9fff4ad29650721bf240 100644 (file)
@@ -2118,7 +2118,7 @@ read_all(tor_socket_t fd, char *buf, size_t count, int isSocket)
     return -1;
   }
 
-  while (numread != count) {
+  while (numread < count) {
     if (isSocket)
       result = tor_socket_recv(fd, buf+numread, count-numread, 0);
     else
@@ -4943,7 +4943,7 @@ tor_read_all_handle(HANDLE h, char *buf, size_t count,
   if (count > SIZE_T_CEILING || count > SSIZE_MAX)
     return -1;
 
-  while (numread != count) {
+  while (numread < count) {
     /* Check if there is anything to read */
     retval = PeekNamedPipe(h, NULL, 0, NULL, &byte_count, NULL);
     if (!retval) {
@@ -5009,7 +5009,7 @@ tor_read_all_handle(int fd, char *buf, size_t count,
   if (count > SIZE_T_CEILING || count > SSIZE_MAX)
     return -1;
 
-  while (numread != count) {
+  while (numread < count) {
     result = read(fd, buf+numread, count-numread);
 
     if (result == 0) {