From 66a3531237e2251f2ed52254be2887224a99dd76 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Wed, 1 Oct 2014 12:53:42 -0400 Subject: [PATCH] Fix BIO_printf on Windows. vsnprintf returns -1 on Windows on truncation, not the needed size. Change-Id: I0a9f32504127b2fb740244c3b59132e201d14234 Reviewed-on: https://boringssl-review.googlesource.com/1870 Reviewed-by: Adam Langley --- crypto/bio/printf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crypto/bio/printf.c b/crypto/bio/printf.c index daebe74c..e1ae5b42 100644 --- a/crypto/bio/printf.c +++ b/crypto/bio/printf.c @@ -75,6 +75,17 @@ int BIO_printf(BIO *bio, const char *format, ...) { out_len = vsnprintf(buf, sizeof(buf), format, args); va_end(args); +#if defined(OPENSSL_WINDOWS) + /* On Windows, vsnprintf returns -1 rather than the requested length on + * truncation */ + if (out_len < 0) { + va_start(args, format); + out_len = _vscprintf(format, args); + va_end(args); + assert(out_len >= sizeof(buf)); + } +#endif + if (out_len >= sizeof(buf)) { const int requested_len = out_len; /* The output was truncated. Note that vsnprintf's return value