summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-03-08 23:02:34 +0100
committerAlexander Færøy <ahf@torproject.org>2017-03-09 00:10:17 +0100
commit02ef06516e64c1559b24123d7c7d164b76110c9a (patch)
tree4c5677250658535f4868cd2a7c089add5d9f0b45 /src/common/util.c
parent0e5c7dc45b9a70ba44dd9a3dc0c3cb38e05e019d (diff)
downloadtor-02ef06516e64c1559b24123d7c7d164b76110c9a.tar.gz
tor-02ef06516e64c1559b24123d7c7d164b76110c9a.zip
Use less-than instead of not-equal-to for comparison in read loops.
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.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 1fd3b16d72..a8b44cbda7 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -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) {