mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
net, tls: use BUF_MAX_LEN
This commit is contained in:
parent
9ce9513898
commit
9e988406c7
@ -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 - 1);
|
||||
tor_assert(read_result <= BUF_MAX_LEN);
|
||||
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 - 1))
|
||||
if (BUG(buf->datalen > BUF_MAX_LEN))
|
||||
return -1;
|
||||
if (BUG(buf->datalen > INT_MAX - 1 - at_most))
|
||||
if (BUG(buf->datalen > BUF_MAX_LEN - 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 - 1);
|
||||
tor_assert(total_read+r <= BUF_MAX_LEN);
|
||||
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 - 1);
|
||||
tor_assert(write_result <= BUF_MAX_LEN);
|
||||
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 - 1);
|
||||
tor_assert(flushed <= BUF_MAX_LEN);
|
||||
return (int)flushed;
|
||||
}
|
||||
|
||||
|
@ -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 - 1)
|
||||
IF_BUG_ONCE(buf->datalen > BUF_MAX_LEN)
|
||||
return TOR_TLS_ERROR_MISC;
|
||||
IF_BUG_ONCE(buf->datalen > INT_MAX - 1 - at_most)
|
||||
IF_BUG_ONCE(buf->datalen > BUF_MAX_LEN - 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 - 1);
|
||||
tor_assert(total_read+r <= BUF_MAX_LEN);
|
||||
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 - 1);
|
||||
tor_assert(flushed <= BUF_MAX_LEN);
|
||||
return (int)flushed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user