net, tls: use INT_MAX - 1 in checks for buf_t

No functionality change.
This commit is contained in:
cypherpunks 2020-03-12 19:15:43 +00:00
parent f46b9320ae
commit bb3eda8617
2 changed files with 10 additions and 10 deletions

View File

@ -76,7 +76,7 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, tor_socket_t fd, size_t at_most,
chunk->datalen += read_result;
log_debug(LD_NET,"Read %ld bytes. %d on inbuf.", (long)read_result,
(int)buf->datalen);
tor_assert(read_result < INT_MAX);
tor_assert(read_result <= INT_MAX - 1);
return (int)read_result;
}
}
@ -103,9 +103,9 @@ buf_read_from_fd(buf_t *buf, int fd, size_t at_most,
tor_assert(reached_eof);
tor_assert(SOCKET_OK(fd));
if (BUG(buf->datalen >= INT_MAX))
if (BUG(buf->datalen > INT_MAX - 1))
return -1;
if (BUG(buf->datalen >= INT_MAX - at_most))
if (BUG(buf->datalen > INT_MAX - 1 - at_most))
return -1;
while (at_most > total_read) {
@ -127,7 +127,7 @@ buf_read_from_fd(buf_t *buf, int fd, size_t at_most,
check();
if (r < 0)
return r; /* Error */
tor_assert(total_read+r < INT_MAX);
tor_assert(total_read+r <= INT_MAX - 1);
total_read += r;
if ((size_t)r < readlen) { /* eof, block, or no more to read. */
break;
@ -170,7 +170,7 @@ flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
} else {
*buf_flushlen -= write_result;
buf_drain(buf, write_result);
tor_assert(write_result < INT_MAX);
tor_assert(write_result <= INT_MAX - 1);
return (int)write_result;
}
}
@ -217,7 +217,7 @@ buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
if (r == 0 || (size_t)r < flushlen0) /* can't flush any more now. */
break;
}
tor_assert(flushed < INT_MAX);
tor_assert(flushed <= INT_MAX - 1);
return (int)flushed;
}

View File

@ -68,9 +68,9 @@ buf_read_from_tls(buf_t *buf, tor_tls_t *tls, size_t at_most)
check_no_tls_errors();
IF_BUG_ONCE(buf->datalen >= INT_MAX)
IF_BUG_ONCE(buf->datalen > INT_MAX - 1)
return TOR_TLS_ERROR_MISC;
IF_BUG_ONCE(buf->datalen >= INT_MAX - at_most)
IF_BUG_ONCE(buf->datalen > INT_MAX - 1 - at_most)
return TOR_TLS_ERROR_MISC;
while (at_most > total_read) {
@ -90,7 +90,7 @@ buf_read_from_tls(buf_t *buf, tor_tls_t *tls, size_t at_most)
r = read_to_chunk_tls(buf, chunk, tls, readlen);
if (r < 0)
return r; /* Error */
tor_assert(total_read+r < INT_MAX);
tor_assert(total_read+r <= INT_MAX - 1);
total_read += r;
if ((size_t)r < readlen) /* eof, block, or no more to read. */
break;
@ -177,6 +177,6 @@ buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
if (r == 0) /* Can't flush any more now. */
break;
} while (sz > 0);
tor_assert(flushed < INT_MAX);
tor_assert(flushed <= INT_MAX - 1);
return (int)flushed;
}