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

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