diff options
author | Robert Ransom <rransom.8774@gmail.com> | 2011-06-15 21:16:44 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-06-17 13:57:25 -0400 |
commit | 68cd0a9abeab126b3d954f060d922fd71cb945f7 (patch) | |
tree | a0aa3d928874849ed9a0fc2c3d0fffd8e558764d /src | |
parent | 39480c797851c8c70914153b403a282a02e7aebb (diff) | |
download | tor-68cd0a9abeab126b3d954f060d922fd71cb945f7.tar tor-68cd0a9abeab126b3d954f060d922fd71cb945f7.tar.gz |
Make connection_printf_to_buf's behaviour sane
Diffstat (limited to 'src')
-rw-r--r-- | src/or/control.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/or/control.c b/src/or/control.c index 5d2d13542..2308cd66f 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -481,33 +481,26 @@ decode_escaped_string(const char *start, size_t in_len_max, } /** Acts like sprintf, but writes its formatted string to the end of - * <b>conn</b>-\>outbuf. The message may be truncated if it is too long, - * but it will always end with a CRLF sequence. - * - * Currently the length of the message is limited to 1024 (including the - * ending CR LF NUL ("\\r\\n\\0"). */ + * <b>conn</b>-\>outbuf. */ static void connection_printf_to_buf(control_connection_t *conn, const char *format, ...) { -#define CONNECTION_PRINTF_TO_BUF_BUFFERSIZE 1024 va_list ap; - char buf[CONNECTION_PRINTF_TO_BUF_BUFFERSIZE]; - int r; - size_t len; + char *buf = NULL; + int len; + va_start(ap,format); - r = tor_vsnprintf(buf, sizeof(buf), format, ap); + len = tor_vasprintf(&buf, format, ap); va_end(ap); - if (r<0) { + + if (len < 0) { log_warn(LD_BUG, "Unable to format string for controller."); return; } - len = strlen(buf); - if (fast_memcmp("\r\n\0", buf+len-2, 3)) { - buf[CONNECTION_PRINTF_TO_BUF_BUFFERSIZE-1] = '\0'; - buf[CONNECTION_PRINTF_TO_BUF_BUFFERSIZE-2] = '\n'; - buf[CONNECTION_PRINTF_TO_BUF_BUFFERSIZE-3] = '\r'; - } - connection_write_to_buf(buf, len, TO_CONN(conn)); + + connection_write_to_buf(buf, (size_t)len, TO_CONN(conn)); + + tor_free(buf); } /** Write all of the open control ports to ControlPortWriteToFile */ |