From 41a6c25a91029cd9358802cc05d96c8c9faeba01 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 12 Feb 2015 12:54:25 +0100 Subject: [PATCH] use vasprintf() in cstp_printf() --- src/tlslib.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tlslib.c b/src/tlslib.c index ec645ade..8db89ce5 100644 --- a/src/tlslib.c +++ b/src/tlslib.c @@ -26,6 +26,9 @@ #include #include #include +#ifndef _GNU_SOURCE +# define _GNU_SOURCE /* for vasprintf() */ +#endif #include #include #include @@ -198,17 +201,19 @@ unsigned tls_has_session_cert(struct worker_st * ws) int __attribute__ ((format(printf, 2, 3))) cstp_printf(worker_st *ws, const char *fmt, ...) { - char buf[1024]; + char *buf; va_list args; - size_t s; - - buf[1023] = 0; + int ret, s; va_start(args, fmt); - s = vsnprintf(buf, 1023, fmt, args); - va_end(args); - return cstp_send(ws, buf, s); + s = vasprintf(&buf, fmt, args); + if (s == -1) + return -1; + va_end(args); + ret = cstp_send(ws, buf, s); + free(buf); + return ret; } void cstp_close(worker_st *ws)