]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Further optimizations in the compression code. Re-enabled the test program by suppres...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 23 Sep 2011 12:22:33 +0000 (14:22 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 23 Sep 2011 12:23:07 +0000 (14:23 +0200)
12 files changed:
NEWS
gl/m4/valgrind-tests.m4
gl/override/m4/valgrind-tests.m4.diff
lib/gnutls_cipher.c
lib/gnutls_compress.c
lib/gnutls_compress.h
lib/gnutls_constate.c
lib/gnutls_int.h
tests/Makefile.am
tests/safe-renegotiation/Makefile.am
tests/safe-renegotiation/suppressions.valgrind [new file with mode: 0644]
tests/suppressions.valgrind [moved from tests/libgcrypt.supp with 88% similarity]

diff --git a/NEWS b/NEWS
index e89105ba1a4966b3751505545fd522aa53795ffb..29502cd0b944703b2ecde8327d10f5d886a0bebb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ See the end for copying conditions.
 
 * Version 3.0.4 (unreleased)
 
+** libgnutls: Fixed the deflate compression code.
+
 ** libgnutls: Added gnutls_x509_crt_get_authority_info_access.
 Used to get the PKIX Authority Information Access (AIA) field.
 
index 98d4487857a91a1b6a1e1a5c6de0cef2be22cb2f..9c4d0290c6b3b8889786eb288662f7c1bf92e6c8 100644 (file)
@@ -23,7 +23,7 @@ AC_DEFUN([gl_VALGRIND_TESTS],
 
   if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
     opt_valgrind_tests=yes
-    VALGRIND="$VALGRIND -q --error-exitcode=1"
+    VALGRIND="$VALGRIND -q --error-exitcode=1 --suppressions=suppressions.valgrind"
   else
     opt_valgrind_tests=no
     VALGRIND=
index 8a4f643af1847fa00477dadefca5d237d234fb1d..dac9a243f6c1e5bf3bb1fcd8287077b781846b7e 100644 (file)
@@ -5,7 +5,7 @@
    if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
      opt_valgrind_tests=yes
 -    VALGRIND="$VALGRIND -q --error-exitcode=1 --leak-check=full"
-+    VALGRIND="$VALGRIND -q --error-exitcode=1"
++    VALGRIND="$VALGRIND -q --error-exitcode=1 --suppressions=suppressions.valgrind"
    else
      opt_valgrind_tests=no
      VALGRIND=
index 75ca6ab090dc29456157f4d2feb9a35a718a10a1..716b7c9bd261ba7e38ab493ab74d34d839d66244 100644 (file)
@@ -105,7 +105,7 @@ _gnutls_encrypt (gnutls_session_t session, const opaque * headers,
       if (comp.data == NULL)
         return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
       
-      ret = _gnutls_compress( params->write.compression_state, data, data_size, comp.data, comp.size);
+      ret = _gnutls_compress( &params->write.compression_state, data, data_size, comp.data, comp.size);
       if (ret < 0)
         {
           gnutls_free(comp.data);
@@ -182,7 +182,7 @@ _gnutls_decrypt (gnutls_session_t session, opaque * ciphertext,
         
       if (ret != 0)
         {
-          ret = _gnutls_decompress(params->read.compression_state, tmp_data, data_size, data, max_data_size);
+          ret = _gnutls_decompress( &params->read.compression_state, tmp_data, data_size, data, max_data_size);
           if (ret < 0)
             goto leave;
         }
index d682511a714f1895d7ddb47f617859eaa0d53884..3821a848798eeed4535e8c8326ede7c4f0bf126e 100644 (file)
@@ -241,20 +241,10 @@ _gnutls_supported_compression_methods (gnutls_session_t session,
 /* The flag d is the direction (compress, decompress). Non zero is
  * decompress.
  */
-comp_hd_t
-_gnutls_comp_init (gnutls_compression_method_t method, int d)
+int _gnutls_comp_init (comp_hd_st* handle, gnutls_compression_method_t method, int d)
 {
-  comp_hd_t ret;
-
-  ret = gnutls_malloc (sizeof (struct comp_hd_t_STRUCT));
-  if (ret == NULL)
-    {
-      gnutls_assert ();
-      return NULL;
-    }
-
-  ret->algo = method;
-  ret->handle = NULL;
+  handle->algo = method;
+  handle->handle = NULL;
 
   switch (method)
     {
@@ -270,14 +260,11 @@ _gnutls_comp_init (gnutls_compression_method_t method, int d)
         mem_level = get_mem_level (method);
         comp_level = get_comp_level (method);
 
-        ret->handle = gnutls_malloc (sizeof (z_stream));
-        if (ret->handle == NULL)
-          {
-            gnutls_assert ();
-            goto cleanup_ret;
-          }
+        handle->handle = gnutls_malloc (sizeof (z_stream));
+        if (handle->handle == NULL)
+          return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 
-        zhandle = ret->handle;
+        zhandle = handle->handle;
 
         zhandle->zalloc = (alloc_func) 0;
         zhandle->zfree = (free_func) 0;
@@ -294,8 +281,8 @@ _gnutls_comp_init (gnutls_compression_method_t method, int d)
         if (err != Z_OK)
           {
             gnutls_assert ();
-            gnutls_free (ret->handle);
-            goto cleanup_ret;
+            gnutls_free (handle->handle);
+            return GNUTLS_E_COMPRESSION_FAILED;
           }
       }
       break;
@@ -303,20 +290,18 @@ _gnutls_comp_init (gnutls_compression_method_t method, int d)
     case GNUTLS_COMP_NULL:
     case GNUTLS_COMP_UNKNOWN:
       break;
+    default:
+      return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
     }
 
-  return ret;
-
-cleanup_ret:
-  gnutls_free (ret);
-  return NULL;
+  return 0;
 }
 
 /* The flag d is the direction (compress, decompress). Non zero is
  * decompress.
  */
 void
-_gnutls_comp_deinit (comp_hd_t handle, int d)
+_gnutls_comp_deinit (comp_hd_st* handle, int d)
 {
   if (handle != NULL)
     {
@@ -336,8 +321,7 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
           break;
         }
       gnutls_free (handle->handle);
-      gnutls_free (handle);
-
+      handle->handle = NULL;
     }
 }
 
@@ -345,7 +329,7 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
  */
 
 int
-_gnutls_compress (comp_hd_handle, const opaque * plain,
+_gnutls_compress (comp_hd_st *handle, const opaque * plain,
                   size_t plain_size, opaque * compressed,
                   size_t max_comp_size)
 {
@@ -399,7 +383,7 @@ _gnutls_compress (comp_hd_t handle, const opaque * plain,
 
 
 int
-_gnutls_decompress (comp_hd_handle, opaque * compressed,
+_gnutls_decompress (comp_hd_st *handle, opaque * compressed,
                     size_t compressed_size, opaque * plain,
                     size_t max_plain_size)
 {
index 7f3545cbd5b10a396e2cfd857eedf0b4403befa6..559906da8b06c3de969bd327a5b0d8acff360574 100644 (file)
@@ -35,19 +35,19 @@ gnutls_compression_method_t _gnutls_compression_get_id (int num);
 
 #define GNUTLS_COMP_FAILED NULL
 
-typedef struct comp_hd_t_STRUCT
+typedef struct comp_hd_st
 {
   void *handle;
   gnutls_compression_method_t algo;
-} *comp_hd_t;
+} comp_hd_st;
 
-comp_hd_t _gnutls_comp_init (gnutls_compression_method_t, int d);
-void _gnutls_comp_deinit (comp_hd_t handle, int d);
+int _gnutls_comp_init (comp_hd_st*, gnutls_compression_method_t, int d);
+void _gnutls_comp_deinit (comp_hd_st* handle, int d);
 
-int _gnutls_decompress (comp_hd_t handle, opaque * compressed,
+int _gnutls_decompress (comp_hd_st* handle, opaque * compressed,
                         size_t compressed_size, opaque * plain,
                         size_t max_plain_size);
-int _gnutls_compress (comp_hd_t, const opaque * plain, size_t plain_size,
+int _gnutls_compress (comp_hd_st*, const opaque * plain, size_t plain_size,
                       opaque * compressed, size_t max_comp_size);
 
 struct gnutls_compression_entry
index d747cc3949b46b911f7620c05f1bfe31f0cbe5b8..6d259401f612e52474a0b37e44d753ac172dfeba 100644 (file)
@@ -306,11 +306,11 @@ _gnutls_init_record_state (record_parameters_st * params, gnutls_protocol_t ver,
   if (ret < 0 && params->cipher_algorithm != GNUTLS_CIPHER_NULL)
     return gnutls_assert_val (ret);
 
-  state->compression_state =
-    _gnutls_comp_init (params->compression_algorithm, read/*1==decompress*/);
+  ret =
+    _gnutls_comp_init (&state->compression_state, params->compression_algorithm, read/*1==decompress*/);
 
-  if (state->compression_state == GNUTLS_COMP_FAILED)
-    return gnutls_assert_val (GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM);
+  if (ret < 0)
+    return gnutls_assert_val (ret);
 
   return 0;
 }
@@ -815,8 +815,8 @@ free_record_state (record_state_st * state, int d)
 
   _gnutls_auth_cipher_deinit (&state->cipher_state);
 
-  if (state->compression_state != NULL)
-    _gnutls_comp_deinit (state->compression_state, d);
+  if (state->compression_state.handle != NULL)
+    _gnutls_comp_deinit (&state->compression_state, d);
 }
 
 void
index 9b0b8bf7c0a83efa1ea2c773c1ad296180051f9a..d47ce5935d9e2898bc719079891e21d0e64810d6 100644 (file)
@@ -495,7 +495,7 @@ struct record_state_st
   gnutls_datum_t IV;
   gnutls_datum_t key;
   auth_cipher_hd_st cipher_state;
-  comp_hd_t compression_state;
+  comp_hd_st compression_state;
   uint64 sequence_number;
 };
 
index 23c0bae0bcea2fa7b7e510d39df3a2c0c823a3d7..08104a70bfcb535ef255c4593072fe43e66ba7df 100644 (file)
@@ -30,7 +30,7 @@ if WANT_TEST_SUITE
 SUBDIRS += suite
 endif
 
-EXTRA_DIST = libgcrypt.supp eagain-common.h
+EXTRA_DIST = suppressions.valgrind eagain-common.h
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
@@ -57,16 +57,15 @@ endif
 noinst_LTLIBRARIES = libutils.la
 libutils_la_SOURCES = utils.h utils.c
 
-ctests = simple gc set_pkcs12_cred certder certuniqueid mpi            \
+ctests = mini-deflate simple gc set_pkcs12_cred certder certuniqueid mpi               \
        certificate_set_x509_crl dn parse_ca moredn mini        \
        hostname-check cve-2008-4989 pkcs12_s2k chainverify crq_key_id  \
        x509sign-verify cve-2009-1415 cve-2009-1416 crq_apis            \
        init_roundtrip pkcs12_s2k_pem dn2 mini-eagain                   \
        nul-in-x509-names x509_altname pkcs12_encode mini-x509          \
        mini-x509-rehandshake rng-fork mini-eagain-dtls cipher-test     \
-       x509cert x509cert-tl infoaccess #gendh mini-deflate
-#gendh is out because it is too slow in valgrind and
-#mini-deflate is out because zlib has warnings in valgrind
+       x509cert x509cert-tl infoaccess #gendh
+#gendh is out because it is too slow in valgrind
 
 if ENABLE_OPENSSL
 ctests +=  openssl
index 8b0c65833aaeac8bd7e480b078f462b3e08be163..17d4684df7143761a02d53daa1f2d6cc91ca48a6 100644 (file)
@@ -32,4 +32,4 @@ check_PROGRAMS = $(ctests)
 TESTS = $(ctests)
 TESTS_ENVIRONMENT = $(VALGRIND)
 
-EXTRA_DIST = README
+EXTRA_DIST = README suppressions.valgrind
diff --git a/tests/safe-renegotiation/suppressions.valgrind b/tests/safe-renegotiation/suppressions.valgrind
new file mode 100644 (file)
index 0000000..e69de29
similarity index 88%
rename from tests/libgcrypt.supp
rename to tests/suppressions.valgrind
index 3766b257026655baf93a1f39cb0a8bc4905fc544..57c4222e2ae106a2ae1da93d51b6aa55290834cc 100644 (file)
@@ -1,11 +1,27 @@
-# libgcrypt.supp -- Valgrind suppresion file for libgcrypt
+# suppressions -- Valgrind suppresion file for libgcrypt
 
-# Copyright (C) 2008, 2009, 2010  Free Software Foundation, Inc.
+# Copyright (C) 2008-2011  Free Software Foundation, Inc.
 
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
+{
+   zlib inflateInit
+   Memcheck:Cond
+   fun:inflateReset2
+   fun:inflateInit2_
+   fun:_gnutls_comp_init
+   fun:_gnutls_init_record_state
+   fun:_gnutls_epoch_set_keys
+   fun:_gnutls_write_connection_state_init
+   fun:_gnutls_send_handshake_final
+   fun:_gnutls_handshake_common
+   fun:gnutls_handshake
+   fun:doit
+   fun:main
+}
+
 {
    libgcrypt1
    Memcheck:Leak