mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
buf: use BUF_MAX_LEN
This commit is contained in:
parent
9e988406c7
commit
64a934ff05
1 changed files with 15 additions and 15 deletions
|
@ -285,7 +285,7 @@ buf_t *
|
||||||
buf_new_with_data(const char *cp, size_t sz)
|
buf_new_with_data(const char *cp, size_t sz)
|
||||||
{
|
{
|
||||||
/* Validate arguments */
|
/* Validate arguments */
|
||||||
if (!cp || sz <= 0 || sz > INT_MAX - 1) {
|
if (!cp || sz <= 0 || sz > BUF_MAX_LEN) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,9 +530,9 @@ buf_add(buf_t *buf, const char *string, size_t string_len)
|
||||||
return (int)buf->datalen;
|
return (int)buf->datalen;
|
||||||
check();
|
check();
|
||||||
|
|
||||||
if (BUG(buf->datalen > INT_MAX - 1))
|
if (BUG(buf->datalen > BUF_MAX_LEN))
|
||||||
return -1;
|
return -1;
|
||||||
if (BUG(buf->datalen > INT_MAX - 1 - string_len))
|
if (BUG(buf->datalen > BUF_MAX_LEN - string_len))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (string_len) {
|
while (string_len) {
|
||||||
|
@ -551,7 +551,7 @@ buf_add(buf_t *buf, const char *string, size_t string_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
check();
|
check();
|
||||||
tor_assert(buf->datalen <= INT_MAX - 1);
|
tor_assert(buf->datalen <= BUF_MAX_LEN);
|
||||||
return (int)buf->datalen;
|
return (int)buf->datalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ buf_get_bytes(buf_t *buf, char *string, size_t string_len)
|
||||||
buf_peek(buf, string, string_len);
|
buf_peek(buf, string, string_len);
|
||||||
buf_drain(buf, string_len);
|
buf_drain(buf, string_len);
|
||||||
check();
|
check();
|
||||||
tor_assert(buf->datalen <= INT_MAX - 1);
|
tor_assert(buf->datalen <= BUF_MAX_LEN);
|
||||||
return (int)buf->datalen;
|
return (int)buf->datalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,9 +660,9 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
|
||||||
char b[4096];
|
char b[4096];
|
||||||
size_t cp, len;
|
size_t cp, len;
|
||||||
|
|
||||||
if (BUG(buf_out->datalen > INT_MAX - 1 || *buf_flushlen > INT_MAX - 1))
|
if (BUG(buf_out->datalen > BUF_MAX_LEN || *buf_flushlen > BUF_MAX_LEN))
|
||||||
return -1;
|
return -1;
|
||||||
if (BUG(buf_out->datalen > INT_MAX - 1 - *buf_flushlen))
|
if (BUG(buf_out->datalen > BUF_MAX_LEN - *buf_flushlen))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
len = *buf_flushlen;
|
len = *buf_flushlen;
|
||||||
|
@ -670,7 +670,7 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
|
||||||
len = buf_in->datalen;
|
len = buf_in->datalen;
|
||||||
|
|
||||||
cp = len; /* Remember the number of bytes we intend to copy. */
|
cp = len; /* Remember the number of bytes we intend to copy. */
|
||||||
tor_assert(cp <= INT_MAX - 1);
|
tor_assert(cp <= BUF_MAX_LEN);
|
||||||
while (len) {
|
while (len) {
|
||||||
/* This isn't the most efficient implementation one could imagine, since
|
/* This isn't the most efficient implementation one could imagine, since
|
||||||
* it does two copies instead of 1, but I kinda doubt that this will be
|
* it does two copies instead of 1, but I kinda doubt that this will be
|
||||||
|
@ -692,9 +692,9 @@ buf_move_all(buf_t *buf_out, buf_t *buf_in)
|
||||||
tor_assert(buf_out);
|
tor_assert(buf_out);
|
||||||
if (!buf_in)
|
if (!buf_in)
|
||||||
return;
|
return;
|
||||||
if (BUG(buf_out->datalen > INT_MAX - 1 || buf_in->datalen > INT_MAX - 1))
|
if (BUG(buf_out->datalen > BUF_MAX_LEN || buf_in->datalen > BUF_MAX_LEN))
|
||||||
return;
|
return;
|
||||||
if (BUG(buf_out->datalen > INT_MAX - 1 - buf_in->datalen))
|
if (BUG(buf_out->datalen > BUF_MAX_LEN - buf_in->datalen))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (buf_out->head == NULL) {
|
if (buf_out->head == NULL) {
|
||||||
|
@ -748,7 +748,7 @@ buf_find_pos_of_char(char ch, buf_pos_t *out)
|
||||||
char *cp = memchr(chunk->data+pos, ch, chunk->datalen - pos);
|
char *cp = memchr(chunk->data+pos, ch, chunk->datalen - pos);
|
||||||
if (cp) {
|
if (cp) {
|
||||||
out->chunk = chunk;
|
out->chunk = chunk;
|
||||||
tor_assert(cp - chunk->data <= INT_MAX - 1);
|
tor_assert(cp - chunk->data <= BUF_MAX_LEN);
|
||||||
out->pos = (int)(cp - chunk->data);
|
out->pos = (int)(cp - chunk->data);
|
||||||
return out->chunk_pos + out->pos;
|
return out->chunk_pos + out->pos;
|
||||||
} else {
|
} else {
|
||||||
|
@ -764,7 +764,7 @@ buf_find_pos_of_char(char ch, buf_pos_t *out)
|
||||||
static inline int
|
static inline int
|
||||||
buf_pos_inc(buf_pos_t *pos)
|
buf_pos_inc(buf_pos_t *pos)
|
||||||
{
|
{
|
||||||
tor_assert(pos->pos < INT_MAX - 1);
|
tor_assert(pos->pos < BUF_MAX_LEN);
|
||||||
++pos->pos;
|
++pos->pos;
|
||||||
if (pos->pos == (ptrdiff_t)pos->chunk->datalen) {
|
if (pos->pos == (ptrdiff_t)pos->chunk->datalen) {
|
||||||
if (!pos->chunk->next)
|
if (!pos->chunk->next)
|
||||||
|
@ -811,7 +811,7 @@ buf_find_string_offset(const buf_t *buf, const char *s, size_t n)
|
||||||
buf_pos_init(buf, &pos);
|
buf_pos_init(buf, &pos);
|
||||||
while (buf_find_pos_of_char(*s, &pos) >= 0) {
|
while (buf_find_pos_of_char(*s, &pos) >= 0) {
|
||||||
if (buf_matches_at_pos(&pos, s, n)) {
|
if (buf_matches_at_pos(&pos, s, n)) {
|
||||||
tor_assert(pos.chunk_pos + pos.pos <= INT_MAX - 1);
|
tor_assert(pos.chunk_pos + pos.pos <= BUF_MAX_LEN);
|
||||||
return (int)(pos.chunk_pos + pos.pos);
|
return (int)(pos.chunk_pos + pos.pos);
|
||||||
} else {
|
} else {
|
||||||
if (buf_pos_inc(&pos)<0)
|
if (buf_pos_inc(&pos)<0)
|
||||||
|
@ -845,7 +845,7 @@ buf_find_offset_of_char(buf_t *buf, char ch)
|
||||||
{
|
{
|
||||||
chunk_t *chunk;
|
chunk_t *chunk;
|
||||||
ptrdiff_t offset = 0;
|
ptrdiff_t offset = 0;
|
||||||
tor_assert(buf->datalen <= INT_MAX - 1);
|
tor_assert(buf->datalen <= BUF_MAX_LEN);
|
||||||
for (chunk = buf->head; chunk; chunk = chunk->next) {
|
for (chunk = buf->head; chunk; chunk = chunk->next) {
|
||||||
char *cp = memchr(chunk->data, ch, chunk->datalen);
|
char *cp = memchr(chunk->data, ch, chunk->datalen);
|
||||||
if (cp)
|
if (cp)
|
||||||
|
@ -915,7 +915,7 @@ buf_assert_ok(buf_t *buf)
|
||||||
for (ch = buf->head; ch; ch = ch->next) {
|
for (ch = buf->head; ch; ch = ch->next) {
|
||||||
total += ch->datalen;
|
total += ch->datalen;
|
||||||
tor_assert(ch->datalen <= ch->memlen);
|
tor_assert(ch->datalen <= ch->memlen);
|
||||||
tor_assert(ch->datalen <= INT_MAX - 1);
|
tor_assert(ch->datalen <= BUF_MAX_LEN);
|
||||||
tor_assert(ch->data >= &ch->mem[0]);
|
tor_assert(ch->data >= &ch->mem[0]);
|
||||||
tor_assert(ch->data <= &ch->mem[0]+ch->memlen);
|
tor_assert(ch->data <= &ch->mem[0]+ch->memlen);
|
||||||
if (ch->data == &ch->mem[0]+ch->memlen) {
|
if (ch->data == &ch->mem[0]+ch->memlen) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue