mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
more friendly warning when a connection buffer overflows
svn:r918
This commit is contained in:
+3
-9
@@ -208,13 +208,13 @@ int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) {
|
||||
|
||||
if (buf_ensure_capacity(buf, at_most+buf->datalen))
|
||||
return -1;
|
||||
|
||||
|
||||
if (at_most > buf->len - buf->datalen)
|
||||
at_most = buf->len - buf->datalen;
|
||||
|
||||
if (at_most == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
r = tor_tls_read(tls, buf->mem+buf->datalen, at_most);
|
||||
if (r<0)
|
||||
return r;
|
||||
@@ -291,15 +291,9 @@ int write_to_buf(const char *string, int string_len, buf_t *buf) {
|
||||
assert(string && BUF_OK(buf));
|
||||
|
||||
if (buf_ensure_capacity(buf, buf->datalen+string_len))
|
||||
log_fn(LOG_WARN, "buflen too small, can't hold %d bytes.",buf->datalen+string_len);
|
||||
return -1;
|
||||
|
||||
/* this is the point where you would grow the buffer, if you want to */
|
||||
|
||||
if (string_len + buf->datalen > buf->len) { /* we're out of luck */
|
||||
log_fn(LOG_WARN, "buflen too small. Time to implement growing dynamic bufs.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(buf->mem+buf->datalen, string, string_len);
|
||||
buf->datalen += string_len;
|
||||
log_fn(LOG_DEBUG,"added %d bytes to buf (now %d total).",string_len, (int)buf->datalen);
|
||||
|
||||
Reference in New Issue
Block a user