aboutsummaryrefslogtreecommitdiff
path: root/src/lib/buf
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2019-07-10 20:39:57 +0200
committerAlexander Færøy <ahf@torproject.org>2019-10-16 17:56:12 +0200
commitd91ad5112e91bfed59bebb657feacac64d34494f (patch)
tree9699c3d10deecbdeec267354a5942d712e2ba2a3 /src/lib/buf
parent1b66668e26764c98d4e5348947a35c1d8ae9f92b (diff)
downloadtor-d91ad5112e91bfed59bebb657feacac64d34494f.tar.gz
tor-d91ad5112e91bfed59bebb657feacac64d34494f.zip
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 <tobias@stoeckmann.org>
Diffstat (limited to 'src/lib/buf')
-rw-r--r--src/lib/buf/buffers.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/lib/buf/buffers.c b/src/lib/buf/buffers.c
index 4d026bd37d..452bf74376 100644
--- a/src/lib/buf/buffers.c
+++ b/src/lib/buf/buffers.c
@@ -578,6 +578,7 @@ buf_add_vprintf(buf_t *buf, const char *format, va_list args)
/* XXXX Faster implementations are easy enough, but let's optimize later */
char *tmp;
tor_vasprintf(&tmp, format, args);
+ tor_assert(tmp != NULL);
buf_add(buf, tmp, strlen(tmp));
tor_free(tmp);
}