From 838ed3c74d247f9220fedffcc366cddc8b995c13 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Tue, 8 Jul 2014 16:24:56 +0200
Subject: [PATCH] Improve interop by not writing ext_len in ClientHello when 0
The RFC also indicates that without any extensions, we should write a
struct {} (empty) not an array of length zero.
---
ChangeLog | 2 ++
library/ssl_cli.c | 7 +++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e24494a61..c4ddcbdc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -49,6 +49,8 @@ Bugfix
* Some example server programs were not sending the close_notify alert.
* Potential memory leak in mpi_exp_mod() when error occurs during
calculation of RR.
+ * Improve interoperability by not writing extension length in ClientHello
+ when no extensions are present (found by Matthew Page)
= Version 1.2.10 released 2013-10-07
Changes
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 2a15da1e9..15fc554b9 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -212,8 +212,11 @@ static int ssl_write_client_hello( ssl_context *ssl )
SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %d",
ext_len ) );
- *p++ = (unsigned char)( ( ext_len >> 8 ) & 0xFF );
- *p++ = (unsigned char)( ( ext_len ) & 0xFF );
+ if( ext_len > 0 )
+ {
+ *p++ = (unsigned char)( ( ext_len >> 8 ) & 0xFF );
+ *p++ = (unsigned char)( ( ext_len ) & 0xFF );
+ }
if ( ssl->hostname != NULL )
{