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

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