From d91ad5112e91bfed59bebb657feacac64d34494f Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Wed, 10 Jul 2019 20:39:57 +0200 Subject: Check tor_vasprintf for error return values. In case of error, a negative value will be returned or NULL written into first supplied argument. This patch uses both cases to comply with style in the specific files. A tor_vasprintf error in process_vprintf would lead to a NULL dereference later on in buf_add, because the return value -1 casted to size_t would pass an assertion check inside of buf_add. On the other hand, common systems will fail on such an operation, so it is not a huge difference to a simple assertion. Yet it is better to properly fail instead of relying on such behaviour on all systems. Signed-off-by: Tobias Stoeckmann --- src/feature/control/control_events.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/feature/control') diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 82ea943999..00659c0477 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1653,7 +1653,10 @@ control_event_status(int type, int severity, const char *format, va_list args) log_warn(LD_BUG, "Format string too long."); return -1; } - tor_vasprintf(&user_buf, format, args); + if (tor_vasprintf(&user_buf, format, args)<0) { + log_warn(LD_BUG, "Failed to create user buffer."); + return -1; + } send_control_event(type, "%s %s\r\n", format_buf, user_buf); tor_free(user_buf); -- cgit v1.2.3-54-g00ecf