From 68cd0a9abeab126b3d954f060d922fd71cb945f7 Mon Sep 17 00:00:00 2001 From: Robert Ransom Date: Wed, 15 Jun 2011 21:16:44 -0700 Subject: Make connection_printf_to_buf's behaviour sane --- changes/fix-connection_printf_to_buf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changes/fix-connection_printf_to_buf (limited to 'changes/fix-connection_printf_to_buf') diff --git a/changes/fix-connection_printf_to_buf b/changes/fix-connection_printf_to_buf new file mode 100644 index 000000000..b6fa0921e --- /dev/null +++ b/changes/fix-connection_printf_to_buf @@ -0,0 +1,10 @@ + * Code simplifications and refactoring: + + - Make connection_printf_to_buf's behaviour sane. Its callers + expect it to emit a CRLF iff the format string ends with CRLF; + it actually emits a CRLF iff (a) the format string ends with + CRLF or (b) the resulting string is over 1023 characters long or + (c) the format string does not end with CRLF ''and'' the + resulting string is 1021 characters long or longer. Bugfix on + 0.1.1.9-alpha; fixes bug 3407. + -- cgit v1.2.3 From 227896e447625b0718690d7228f1239a0fc399d1 Mon Sep 17 00:00:00 2001 From: Robert Ransom Date: Thu, 16 Jun 2011 03:39:37 -0700 Subject: Make send_control_event_impl's behaviour sane --- changes/fix-connection_printf_to_buf | 7 ++++++- src/or/control.c | 31 ++++++++----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) (limited to 'changes/fix-connection_printf_to_buf') diff --git a/changes/fix-connection_printf_to_buf b/changes/fix-connection_printf_to_buf index b6fa0921e..e191eac8a 100644 --- a/changes/fix-connection_printf_to_buf +++ b/changes/fix-connection_printf_to_buf @@ -6,5 +6,10 @@ CRLF or (b) the resulting string is over 1023 characters long or (c) the format string does not end with CRLF ''and'' the resulting string is 1021 characters long or longer. Bugfix on - 0.1.1.9-alpha; fixes bug 3407. + 0.1.1.9-alpha; fixes part of bug 3407. + + - Make send_control_event_impl's behaviour sane. Its callers + expect it to always emit a CRLF at the end of the string; it + might emit extra control characters as well. Bugfix on + 0.1.1.9-alpha; fixes another part of bug 3407. diff --git a/src/or/control.c b/src/or/control.c index 2170a9b94..e7d204473 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -602,43 +602,28 @@ send_control_event_string(uint16_t event, event_format_t which, /** Helper for send_control_event and control_event_status: * Send an event to all v1 controllers that are listening for code * event. The event's body is created by the printf-style format in - * format, and other arguments as provided. - * - * Currently the length of the message is limited to 10064 (including the - * ending \\r\\n\\0). */ + * format, and other arguments as provided. */ static void send_control_event_impl(uint16_t event, event_format_t which, const char *format, va_list ap) { - /* This is just a little longer than the longest allowed log message */ -#define SEND_CONTROL1_EVENT_BUFFERSIZE 10064 - int r; - char buf[SEND_CONTROL1_EVENT_BUFFERSIZE]; - size_t len; + char *buf = NULL; + int len; - r = tor_vsnprintf(buf, sizeof(buf), format, ap); - if (r<0) { + len = tor_vasprintf(&buf, format, ap); + if (len < 0) { log_warn(LD_BUG, "Unable to format event for controller."); return; } - len = strlen(buf); - if (fast_memcmp("\r\n\0", buf+len-2, 3)) { - /* if it is not properly terminated, do it now */ - buf[SEND_CONTROL1_EVENT_BUFFERSIZE-1] = '\0'; - buf[SEND_CONTROL1_EVENT_BUFFERSIZE-2] = '\n'; - buf[SEND_CONTROL1_EVENT_BUFFERSIZE-3] = '\r'; - } - send_control_event_string(event, which|ALL_FORMATS, buf); + + tor_free(buf); } /** Send an event to all v1 controllers that are listening for code * event. The event's body is created by the printf-style format in - * format, and other arguments as provided. - * - * Currently the length of the message is limited to 10064 (including the - * ending \\n\\r\\0. */ + * format, and other arguments as provided. */ static void send_control_event(uint16_t event, event_format_t which, const char *format, ...) -- cgit v1.2.3