From 064483035c01e7f34d4f7a735e225c4c72d1c3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Guimar=C3=A3es?= Date: Mon, 9 Jun 2014 17:31:32 -0300 Subject: [PATCH] fix on TLSX_SNI_GetFromBuffer - set inOutSz value to zero when there is no SNI extension in the client hello buffer. --- src/tls.c | 2 ++ tests/api.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tls.c b/src/tls.c index 420ea15ba..45de6a8ef 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1047,6 +1047,8 @@ int TLSX_SNI_GetFromBuffer(const byte* clientHello, word32 helloSz, len16 -= min(2 * OPAQUE16_LEN + extLen, len16); } + *inOutSz = 0; + return len16 ? BUFFER_ERROR : SSL_SUCCESS; } diff --git a/tests/api.c b/tests/api.c index 200fca2e1..a0a6f781b 100644 --- a/tests/api.c +++ b/tests/api.c @@ -390,9 +390,15 @@ static void test_CyaSSL_SNI_GetFromBuffer(void) AssertIntEQ(SSL_SUCCESS, CyaSSL_SNI_GetFromBuffer(buffer3, sizeof(buffer3), 0, result, &length)); + AssertIntEQ(XSTRLEN(""), length); + + length = 32; AssertIntEQ(SSL_SUCCESS, CyaSSL_SNI_GetFromBuffer(buffer2, sizeof(buffer2), 1, result, &length)); + AssertIntEQ(XSTRLEN(""), length); + + length = 32; AssertIntEQ(-228, CyaSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, result, &length)); @@ -410,15 +416,15 @@ static void test_CyaSSL_SNI_GetFromBuffer(void) result, &length)); buffer[4] = 0x64; - AssertIntEQ(1, CyaSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, - result, &length)); + AssertIntEQ(SSL_SUCCESS, CyaSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), + 0, result, &length)); result[length] = 0; AssertStrEQ("www.paypal.com", (const char*) result); length = 32; - AssertIntEQ(1, CyaSSL_SNI_GetFromBuffer(buffer2, sizeof(buffer2), 0, - result, &length)); + AssertIntEQ(SSL_SUCCESS, CyaSSL_SNI_GetFromBuffer(buffer2, sizeof(buffer2), + 0, result, &length)); result[length] = 0; AssertStrEQ("api.textmate.org", (const char*) result); }