From ac03052f22f9cb995836c46920c30b4170da9ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 2 Sep 2014 14:23:40 +0200 Subject: [PATCH] Fix segfault with some very short fragments --- library/ssl_tls.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 39d93f9c3..d73333a78 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2140,6 +2140,16 @@ static void ssl_bitmask_set( unsigned char *mask, size_t offset, size_t len ) { size_t first_byte_idx = offset / 8; + /* Special case */ + if( len <= start_bits ) + { + for( ; len != 0; len-- ) + mask[first_byte_idx] |= 1 << ( start_bits - len ); + + /* Avoid potential issues with offset or len becoming invalid */ + return; + } + offset += start_bits; /* Now offset % 8 == 0 */ len -= start_bits;