summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-08-24 09:27:26 -0400
committerNick Mathewson <nickm@torproject.org>2017-08-24 09:27:26 -0400
commit35a29e81aea1712caada533dbdab4248612cc185 (patch)
treeb5c64497d6bf13c39b751d83035721832220715b /src/or/control.c
parentd37e8b407a762316e89e0c0a613c26372ec897aa (diff)
parent6f7d548bc428a5aa923c04cdcdab59af88a3495b (diff)
downloadtor-35a29e81aea1712caada533dbdab4248612cc185.tar.gz
tor-35a29e81aea1712caada533dbdab4248612cc185.zip
Merge branch 'bug19281_025'
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 724d4b35c0..87d6d00fcc 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -368,16 +368,23 @@ connection_write_str_to_buf(const char *s, control_connection_t *conn)
STATIC size_t
write_escaped_data(const char *data, size_t len, char **out)
{
- size_t sz_out = len+8;
+ tor_assert(len < SIZE_MAX - 9);
+ size_t sz_out = len+8+1;
char *outp;
const char *start = data, *end;
- int i;
+ size_t i;
int start_of_line;
- for (i=0; i<(int)len; ++i) {
- if (data[i]== '\n')
+ for (i=0; i < len; ++i) {
+ if (data[i] == '\n') {
sz_out += 2; /* Maybe add a CR; maybe add a dot. */
+ if (sz_out >= SIZE_T_CEILING) {
+ log_warn(LD_BUG, "Input to write_escaped_data was too long");
+ *out = tor_strdup(".\r\n");
+ return 3;
+ }
+ }
}
- *out = outp = tor_malloc(sz_out+1);
+ *out = outp = tor_malloc(sz_out);
end = data+len;
start_of_line = 1;
while (data < end) {
@@ -403,7 +410,8 @@ write_escaped_data(const char *data, size_t len, char **out)
*outp++ = '\r';
*outp++ = '\n';
*outp = '\0'; /* NUL-terminate just in case. */
- tor_assert((outp - *out) <= (int)sz_out);
+ tor_assert(outp >= *out);
+ tor_assert((size_t)(outp - *out) <= sz_out);
return outp - *out;
}