8245999
diff -up gnutls-1.4.1/lib/ext_server_name.c.sa-2008-1 gnutls-1.4.1/lib/ext_server_name.c
8245999
--- gnutls-1.4.1/lib/ext_server_name.c.sa-2008-1	2006-03-08 11:44:59.000000000 +0100
8245999
+++ gnutls-1.4.1/lib/ext_server_name.c	2008-05-20 09:52:13.000000000 +0200
8245999
@@ -74,10 +74,27 @@ _gnutls_server_name_recv_params (gnutls_
8245999
 	  len = _gnutls_read_uint16 (p);
8245999
 	  p += 2;
8245999
 
8245999
-	  DECR_LENGTH_RET (data_size, len, 0);
8245999
-	  server_names++;
8245999
+	  if (len > 0)
8245999
+	    {
8245999
+	      DECR_LENGTH_RET (data_size, len, 0);
8245999
+	      server_names++;
8245999
+	      p += len;
8245999
+	    }
8245999
+	  else
8245999
+	    _gnutls_handshake_log
8245999
+	      ("HSK[%x]: Received zero size server name (under attack?)\n",
8245999
+	       session);
8245999
 
8245999
-	  p += len;
8245999
+	}
8245999
+
8245999
+      /* we cannot accept more server names.
8245999
+       */
8245999
+      if (server_names > MAX_SERVER_NAME_EXTENSIONS)
8245999
+	{
8245999
+	  _gnutls_handshake_log
8245999
+	    ("HSK[%x]: Too many server names received (under attack?)\n",
8245999
+	     session);
8245999
+	  server_names = MAX_SERVER_NAME_EXTENSIONS;
8245999
 	}
8245999
 
8245999
       session->security_parameters.extensions.server_names_size =
8245999
@@ -85,10 +102,6 @@ _gnutls_server_name_recv_params (gnutls_
8245999
       if (server_names == 0)
8245999
 	return 0;		/* no names found */
8245999
 
8245999
-      /* we cannot accept more server names.
8245999
-       */
8245999
-      if (server_names > MAX_SERVER_NAME_EXTENSIONS)
8245999
-	server_names = MAX_SERVER_NAME_EXTENSIONS;
8245999
 
8245999
       p = data + 2;
8245999
       for (i = 0; i < server_names; i++)
8245999
diff -up gnutls-1.4.1/lib/gnutls_handshake.c.sa-2008-1 gnutls-1.4.1/lib/gnutls_handshake.c
8245999
--- gnutls-1.4.1/lib/gnutls_handshake.c.sa-2008-1	2006-04-17 18:32:16.000000000 +0200
8245999
+++ gnutls-1.4.1/lib/gnutls_handshake.c	2008-05-20 09:52:13.000000000 +0200
8245999
@@ -929,6 +929,14 @@ _gnutls_recv_handshake_header (gnutls_se
8245999
 
8245999
       *recv_type = session->internals.handshake_header_buffer.recv_type;
8245999
 
8245999
+      if (*recv_type != type)
8245999
+	{
8245999
+	  gnutls_assert ();
8245999
+	  _gnutls_handshake_log
8245999
+	    ("HSK[%x]: Handshake type mismatch (under attack?)\n", session);
8245999
+	  return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
8245999
+	}
8245999
+
8245999
       return session->internals.handshake_header_buffer.packet_length;
8245999
     }
8245999
 
8245999
diff -up gnutls-1.4.1/lib/gnutls_cipher.c.sa-2008-1 gnutls-1.4.1/lib/gnutls_cipher.c
8245999
--- gnutls-1.4.1/lib/gnutls_cipher.c.sa-2008-1	2006-03-08 11:44:59.000000000 +0100
8245999
+++ gnutls-1.4.1/lib/gnutls_cipher.c	2008-05-20 09:52:48.000000000 +0200
8245999
@@ -445,7 +445,6 @@ _gnutls_ciphertext2compressed (gnutls_se
8245999
       return GNUTLS_E_INTERNAL_ERROR;
8245999
     }
8245999
 
8245999
-
8245999
   /* actual decryption (inplace)
8245999
    */
8245999
   switch (_gnutls_cipher_is_block
8245999
@@ -496,17 +495,20 @@ _gnutls_ciphertext2compressed (gnutls_se
8245999
 
8245999
       pad = ciphertext.data[ciphertext.size - 1] + 1;	/* pad */
8245999
 
8245999
-      length = ciphertext.size - hash_size - pad;
8245999
-
8245999
-      if (pad > ciphertext.size - hash_size)
8245999
+      if ((int)pad > (int)ciphertext.size - hash_size)
8245999
 	{
8245999
 	  gnutls_assert ();
8245999
+	  _gnutls_record_log
8245999
+	    ("REC[%x]: Short record length %d > %d - %d (under attack?)\n",
8245999
+	     session, pad, ciphertext.size, hash_size);
8245999
 	  /* We do not fail here. We check below for the
8245999
 	   * the pad_failed. If zero means success.
8245999
 	   */
8245999
 	  pad_failed = GNUTLS_E_DECRYPTION_FAILED;
8245999
 	}
8245999
 
8245999
+      length = ciphertext.size - hash_size - pad;
8245999
+
8245999
       /* Check the pading bytes (TLS 1.x)
8245999
        */
8245999
       if (ver >= GNUTLS_TLS1 && pad_failed == 0)