From 10e6e7fbb5a05719522442de0681e63f65134f33 Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 20 May 2013 10:36:06 -0700 Subject: [PATCH] check error_string_n size and truncate if too short --- src/ssl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ssl.c b/src/ssl.c index d208c7be8..742410602 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -632,7 +632,18 @@ char* CyaSSL_ERR_error_string(unsigned long errNumber, char* data) void CyaSSL_ERR_error_string_n(unsigned long e, char* buf, unsigned long len) { CYASSL_ENTER("CyaSSL_ERR_error_string_n"); - if (len) CyaSSL_ERR_error_string(e, buf); + if (len >= MAX_ERROR_SZ) + CyaSSL_ERR_error_string(e, buf); + else { + char tmp[MAX_ERROR_SZ]; + + CYASSL_MSG("Error buffer too short, truncating"); + if (len) { + CyaSSL_ERR_error_string(e, tmp); + XMEMCPY(buf, tmp, len-1); + buf[len-1] = '\0'; + } + } }