diff options
author | David Benjamin <davidben@chromium.org> | 2014-10-01 12:53:42 -0400 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2014-10-01 17:22:56 +0000 |
commit | 66a3531237e2251f2ed52254be2887224a99dd76 (patch) | |
tree | dde3085f42a1b4c7f1fad11b77eccd3c5eb54a62 /crypto | |
parent | fb3ff2c66cc873150022a4ab87ac72dd9d78b549 (diff) | |
download | src-66a3531237e2251f2ed52254be2887224a99dd76.tar.gz |
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 <agl@google.com>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/bio/printf.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/crypto/bio/printf.c b/crypto/bio/printf.c index daebe74..e1ae5b4 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 |