Blame SOURCES/net-snmp-5.8-memleak-backport.patch

058f5d
From c6facf2f080c9e1ea803e4884dc92889ec83d990 Mon Sep 17 00:00:00 2001
058f5d
From: Drew A Roedersheimer <Drew.A.Roedersheimer@leidos.com>
058f5d
Date: Wed, 10 Oct 2018 21:42:35 -0700
058f5d
Subject: [PATCH] snmplib/keytools: Fix a memory leak
058f5d
058f5d
Avoid that Valgrind reports the following memory leak:
058f5d
058f5d
17,328 bytes in 361 blocks are definitely lost in loss record 696 of 704
058f5d
   at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
058f5d
   by 0x52223B7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.2k)
058f5d
   by 0x52DDB06: EVP_MD_CTX_create (in /usr/lib64/libcrypto.so.1.0.2k)
058f5d
   by 0x4E9885D: generate_Ku (keytools.c:186)
058f5d
   by 0x40171F: asynchronous (leaktest.c:276)
058f5d
   by 0x400FE7: main (leaktest.c:356)
058f5d
---
058f5d
 snmplib/keytools.c | 12 ++++++++----
058f5d
 1 file changed, 8 insertions(+), 4 deletions(-)
058f5d
058f5d
diff --git a/snmplib/keytools.c b/snmplib/keytools.c
058f5d
index 2cf0240abf..dcdae044ac 100644
058f5d
--- a/snmplib/keytools.c
058f5d
+++ b/snmplib/keytools.c
058f5d
@@ -186,11 +186,15 @@ generate_Ku(const oid * hashtype, u_int hashtype_len,
058f5d
     ctx = EVP_MD_CTX_create();
058f5d
 #else
058f5d
     ctx = malloc(sizeof(*ctx));
058f5d
-    if (!EVP_MD_CTX_init(ctx))
058f5d
-        return SNMPERR_GENERR;
058f5d
+    if (!EVP_MD_CTX_init(ctx)) {
058f5d
+        rval = SNMPERR_GENERR;
058f5d
+        goto generate_Ku_quit;
058f5d
+    }
058f5d
 #endif
058f5d
-    if (!EVP_DigestInit(ctx, hashfn))
058f5d
-        return SNMPERR_GENERR;
058f5d
+    if (!EVP_DigestInit(ctx, hashfn)) {
058f5d
+        rval = SNMPERR_GENERR;
058f5d
+        goto generate_Ku_quit;
058f5d
+    }
058f5d
 
058f5d
 #elif NETSNMP_USE_INTERNAL_CRYPTO
058f5d
 #ifndef NETSNMP_DISABLE_MD5
058f5d
From 67726f2a74007b5b4117fe49ca1e02c86110b624 Mon Sep 17 00:00:00 2001
058f5d
From: Drew A Roedersheimer <Drew.A.Roedersheimer@leidos.com>
058f5d
Date: Tue, 9 Oct 2018 23:28:25 +0000
058f5d
Subject: [PATCH] snmplib: Fix a memory leak in scapi.c
058f5d
058f5d
This patch avoids that Valgrind reports the following leak:
058f5d
058f5d
==1069== 3,456 bytes in 72 blocks are definitely lost in loss record 1,568 of 1,616
058f5d
==1069==    at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
058f5d
==1069==    by 0x70A63B7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.2k)
058f5d
==1069==    by 0x7161B06: EVP_MD_CTX_create (in /usr/lib64/libcrypto.so.1.0.2k)
058f5d
==1069==    by 0x4EA3017: sc_hash (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4EA1CD8: hash_engineID (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4EA1DEC: search_enginetime_list (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4EA2256: set_enginetime (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4EC495E: usm_process_in_msg (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4EC58CA: usm_secmod_process_in_msg (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4E7B91D: snmpv3_parse (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4E7C1F6: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
==1069==    by 0x4E7CE94: ??? (in /usr/lib64/libnetsnmp.so.31.0.2)
058f5d
058f5d
[ bvanassche: minimized diffs / edited commit message ]
058f5d
---
058f5d
 snmplib/scapi.c | 5 ++++-
058f5d
 1 file changed, 4 insertions(+), 1 deletion(-)
058f5d
058f5d
diff --git a/snmplib/scapi.c b/snmplib/scapi.c
058f5d
index 8ad1d70d90..54310099d8 100644
058f5d
--- a/snmplib/scapi.c
058f5d
+++ b/snmplib/scapi.c
058f5d
@@ -967,7 +967,8 @@ sc_hash_type(int auth_type, const u_char * buf, size_t buf_len, u_char * MAC,
058f5d
 #endif
058f5d
     if (!EVP_DigestInit(cptr, hashfn)) {
058f5d
         /* requested hash function is not available */
058f5d
-        return SNMPERR_SC_NOT_CONFIGURED;
058f5d
+        rval = SNMPERR_SC_NOT_CONFIGURED;
058f5d
+        goto sc_hash_type_quit;
058f5d
     }
058f5d
 
058f5d
 /** pass the data */
058f5d
@@ -976,6 +977,8 @@ sc_hash_type(int auth_type, const u_char * buf, size_t buf_len, u_char * MAC,
058f5d
 /** do the final pass */
058f5d
     EVP_DigestFinal(cptr, MAC, &tmp_len);
058f5d
     *MAC_len = tmp_len;
058f5d
+
058f5d
+sc_hash_type_quit:
058f5d
 #if defined(HAVE_EVP_MD_CTX_FREE)
058f5d
     EVP_MD_CTX_free(cptr);
058f5d
 #elif defined(HAVE_EVP_MD_CTX_DESTROY)
058f5d