[pkg-opensc-commit] [opensc] 08/23: libopensc: avoid call to memset() with zero length

Eric Dorland eric at moszumanska.debian.org
Tue Jul 5 06:01:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 0e1c8f9c0477a42c53de2ad93bc1a26a1820e642
Author: Viktor Tarasov <viktor.tarasov at gmail.com>
Date:   Mon May 23 11:00:12 2016 +0200

    libopensc: avoid call to memset() with zero length
    
    @mouse07410 has asked for it in
    https://github.com/OpenSC/OpenSC/issues/688#issuecomment-219433611
    
    VTA: I do not see the difference (if the other arguments are properly used),
    but assume that @mouse07410 has it's own valid reasons
    
    Also included the few coding style touches.
---
 src/libopensc/sc.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c
index e6e7104..b4db30d 100644
--- a/src/libopensc/sc.c
+++ b/src/libopensc/sc.c
@@ -806,12 +806,12 @@ void *sc_mem_alloc_secure(sc_context_t *ctx, size_t len)
 
     pointer = calloc(len, sizeof(unsigned char));
     if (!pointer)
-        return NULL;
+	return NULL;
 #ifdef HAVE_SYS_MMAN_H
     /* TODO mprotect */
     /* Do not swap the memory */
     if (mlock(pointer, len) >= 0)
-        locked = 1;
+	locked = 1;
 #endif
 #ifdef _WIN32
 	/* Do not swap the memory */
@@ -819,26 +819,27 @@ void *sc_mem_alloc_secure(sc_context_t *ctx, size_t len)
 		locked = 1;
 #endif
     if (!locked) {
-        if (ctx->flags & SC_CTX_FLAG_PARANOID_MEMORY) {
-            sc_do_log (ctx, 0, NULL, 0, NULL, "cannot lock memory, failing allocation because paranoid set");
-            free (pointer);
-            pointer = NULL;
-        } else {
-            sc_do_log (ctx, 0, NULL, 0, NULL, "cannot lock memory, sensitive data may be paged to disk");
-        }
+	if (ctx->flags & SC_CTX_FLAG_PARANOID_MEMORY) {
+	    sc_do_log (ctx, 0, NULL, 0, NULL, "cannot lock memory, failing allocation because paranoid set");
+	    free (pointer);
+	    pointer = NULL;
+	} else {
+	    sc_do_log (ctx, 0, NULL, 0, NULL, "cannot lock memory, sensitive data may be paged to disk");
+	}
     }
     return pointer;
 }
 
 void sc_mem_clear(void *ptr, size_t len)
 {
-#ifdef ENABLE_OPENSSL
 	/* FIXME: Bug in 1.0.0-beta series crashes with 0 length */
-	if (len > 0)
+	if (len > 0)   {
+#ifdef ENABLE_OPENSSL
 		OPENSSL_cleanse(ptr, len);
 #else
-	memset(ptr, 0, len);
+		memset(ptr, 0, len);
 #endif
+	}
 }
 
 int sc_mem_reverse(unsigned char *buf, size_t len)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list