diff options
author | George Kadianakis <desnacked@riseup.net> | 2020-11-03 16:06:12 +0200 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2020-11-03 16:06:12 +0200 |
commit | dd119b277b66c1a7209d4a345fd43878296a532e (patch) | |
tree | f9782f5eb7c795cd0570fb9516380d915b56ac10 /src/feature/control | |
parent | 4f5a116618fdb1707905c2fc602a216f7da22e6e (diff) | |
parent | 511822529ae1710e141bc26199ec5ff1d1abcd16 (diff) | |
download | tor-dd119b277b66c1a7209d4a345fd43878296a532e.tar.gz tor-dd119b277b66c1a7209d4a345fd43878296a532e.zip |
Merge remote-tracking branch 'tor-gitlab/mr/185' into master
Diffstat (limited to 'src/feature/control')
-rw-r--r-- | src/feature/control/control_events.c | 26 | ||||
-rw-r--r-- | src/feature/control/control_events.h | 2 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 2970745ca0..0dd52659ec 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1352,6 +1352,27 @@ enable_control_logging(void) tor_assert(0); } +/** Remove newline and carriage-return characters from @a msg, replacing them + * with spaces, and discarding any that appear at the end of the message */ +void +control_logmsg_strip_newlines(char *msg) +{ + char *cp; + for (cp = msg; *cp; ++cp) { + if (*cp == '\r' || *cp == '\n') { + *cp = ' '; + } + } + if (cp == msg) + return; + /* Remove trailing spaces */ + for (--cp; *cp == ' '; --cp) { + *cp = '\0'; + if (cp == msg) + break; + } +} + /** We got a log message: tell any interested control connections. */ void control_event_logmsg(int severity, log_domain_mask_t domain, const char *msg) @@ -1380,11 +1401,8 @@ control_event_logmsg(int severity, log_domain_mask_t domain, const char *msg) char *b = NULL; const char *s; if (strchr(msg, '\n')) { - char *cp; b = tor_strdup(msg); - for (cp = b; *cp; ++cp) - if (*cp == '\r' || *cp == '\n') - *cp = ' '; + control_logmsg_strip_newlines(b); } switch (severity) { case LOG_DEBUG: s = "DEBUG"; break; diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index 6e3cfef4e9..0ac233cc6e 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -341,6 +341,8 @@ struct control_event_t { extern const struct control_event_t control_event_table[]; +void control_logmsg_strip_newlines(char *msg); + #ifdef TOR_UNIT_TESTS MOCK_DECL(STATIC void, send_control_event_string,(uint16_t event, const char *msg)); |