[git] GCRYPT - branch, master, updated. post-nuke-of-trailing-ws-30-g1351cc9

by Werner Koch cvs at cvs.gnupg.org
Tue Apr 19 16:55:05 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  1351cc95b5ee70fde396f8d5754214ef6db4baec (commit)
      from  8ecc5614cc40a2d37c3ca704d06470a38c76983d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1351cc95b5ee70fde396f8d5754214ef6db4baec
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 19 16:22:48 2011 +0200

    Make sure to return correct error codes for secmem failures.
    
    ERRNO was not always set and thus it could happen that a misleading
    error code was returned form a malloc functions.  Fix was to set
    ERRNO.
    
    At one place we also switched to the newer gpg_err_code_from_syserror
    which makes sure to return a special error code in case ERRNO is not
    set at all.

diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 2a28b20..fb05141 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,8 @@
+2011-04-19  Werner Koch  <wk at g10code.com>
+
+	* cipher.c (gcry_cipher_open): Replace gpg_err_code_from_errno by
+	gpg_err_code_from_syserror.
+
 2011-04-11  Werner Koch  <wk at g10code.com>
 
 	* pubkey.c (gcry_pk_get_keygrip): Avoid double free of L2.
diff --git a/cipher/cipher.c b/cipher/cipher.c
index 90fdb17..b0a532a 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -786,7 +786,7 @@ gcry_cipher_open (gcry_cipher_hd_t *handle,
 	h = gcry_calloc (1, size);
 
       if (! h)
-	err = gpg_err_code_from_errno (errno);
+	err = gpg_err_code_from_syserror ();
       else
 	{
           size_t off = 0;
diff --git a/src/ChangeLog b/src/ChangeLog
index 9476e82..2907e85 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2011-04-19  Werner Koch  <wk at g10code.com>
+
+	* stdmem.c (_gcry_private_malloc_secure, _gcry_private_malloc):
+	Set ERRNO on failure.
+	* secmem.c (mb_get_new): Set ERRNO on failure.
+	(_gcry_secmem_malloc_internal): Ditto.
+
 2011-04-01  Werner Koch  <wk at g10code.com>
 
 	* global.c (gcry_realloc): Divert to gcry_malloc or gcry_free.
diff --git a/src/secmem.c b/src/secmem.c
index 30c2777..2beb234 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -217,7 +217,10 @@ mb_get_new (memblock_t *block, size_t size)
       }
 
   if (! ptr_into_pool_p (mb))
-    mb = NULL;
+    {
+      gpg_err_set_errno (ENOMEM);
+      mb = NULL;
+    }
 
   return mb;
 }
@@ -516,12 +519,14 @@ _gcry_secmem_malloc_internal (size_t size)
         {
           log_info (_("operation is not possible without "
                       "initialized secure memory\n"));
+          gpg_err_set_errno (ENOMEM);
           return NULL;
         }
     }
   if (not_locked && fips_mode ())
     {
       log_info (_("secure memory pool is not locked while in FIPS mode\n"));
+      gpg_err_set_errno (ENOMEM);
       return NULL;
     }
   if (show_warning && !suspend_warning)
diff --git a/src/stdmem.c b/src/stdmem.c
index c20c4b4..189da37 100644
--- a/src/stdmem.c
+++ b/src/stdmem.c
@@ -49,6 +49,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <errno.h>
 
 #include "g10lib.h"
 #include "stdmem.h"
@@ -88,8 +89,12 @@ void *
 _gcry_private_malloc (size_t n)
 {
   if (!n)
-    return NULL; /* Allocating 0 bytes is undefined - we better return
-                    an error to detect such coding errors.  */
+    {
+      gpg_err_set_errno (EINVAL);
+      return NULL; /* Allocating 0 bytes is undefined - we better return
+                      an error to detect such coding errors.  */
+    }
+
   if (use_m_guard)
     {
       char *p;
@@ -118,8 +123,12 @@ void *
 _gcry_private_malloc_secure (size_t n)
 {
   if (!n)
-    return NULL; /* Allocating 0 bytes is undefined - better return an
-                    error to detect such coding errors.  */
+    {
+      gpg_err_set_errno (EINVAL);
+      return NULL; /* Allocating 0 bytes is undefined - better return an
+                      error to detect such coding errors.  */
+    }
+
   if (use_m_guard)
     {
       char *p;

-----------------------------------------------------------------------

Summary of changes:
 cipher/ChangeLog |    5 +++++
 cipher/cipher.c  |    2 +-
 src/ChangeLog    |    7 +++++++
 src/secmem.c     |    7 ++++++-
 src/stdmem.c     |   17 +++++++++++++----
 5 files changed, 32 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org




More information about the Gnupg-commits mailing list