Blame SOURCES/0046-Ticket-49493-heap-use-after-free-in-csn_as_string.patch

96373c
From a7a0db402b32dcec7fc93bcbef42174163ae9c12 Mon Sep 17 00:00:00 2001
96373c
From: Ludwig Krispenz <lkrispen@redhat.com>
96373c
Date: Tue, 12 Dec 2017 12:46:37 +0100
96373c
Subject: [PATCH] Ticket 49493 - heap use after free in csn_as_string
96373c
96373c
Bug: If write_changlog_and_ruv failed teh csn pending list was not properly
96373c
     cleand and references to the prim csn were kept, but the prim csn was reset
96373c
96373c
Fix: check the return code for the mmr postop plugin and aset error codes properly
96373c
     that will triger cancel_opcsn
96373c
96373c
Reviewed by: Thierry, thanks
96373c
Tested by: Viktor, thanks
96373c
---
96373c
 ldap/servers/slapd/back-ldbm/ldbm_add.c        | 22 +---------------------
96373c
 ldap/servers/slapd/back-ldbm/ldbm_delete.c     |  4 ++++
96373c
 ldap/servers/slapd/back-ldbm/ldbm_modify.c     |  4 ++++
96373c
 ldap/servers/slapd/back-ldbm/ldbm_modrdn.c     |  4 ++++
96373c
 ldap/servers/slapd/back-ldbm/misc.c            | 18 ++++++++++++++++++
96373c
 ldap/servers/slapd/back-ldbm/proto-back-ldbm.h |  1 +
96373c
 6 files changed, 32 insertions(+), 21 deletions(-)
96373c
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
index b7e17ad50..f29945a7e 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
@@ -22,7 +22,6 @@ extern char *hassubordinates;
96373c
 
96373c
 static void delete_update_entrydn_operational_attributes(struct backentry *ep);
96373c
 
96373c
-static int set_error(Slapi_PBlock *pb, int retval, int ldap_result_code, char **ldap_result_message);
96373c
 #define ADD_SET_ERROR(rc, error, count)                                            \
96373c
     {                                                                              \
96373c
         (rc) = (error);                                                            \
96373c
@@ -1201,7 +1200,7 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
 
96373c
     retval = plugin_call_mmr_plugin_postop(pb, NULL,SLAPI_PLUGIN_BE_TXN_POST_ADD_FN);
96373c
     if (retval) {
96373c
-        set_error(pb, retval, ldap_result_code, &ldap_result_message);
96373c
+        ldbm_set_error(pb, retval, &ldap_result_code, &ldap_result_message);
96373c
         goto error_return;
96373c
     }
96373c
 
96373c
@@ -1471,22 +1470,3 @@ delete_update_entrydn_operational_attributes(struct backentry *ep)
96373c
     slapi_entry_attr_delete(ep->ep_entry, LDBM_ENTRYDN_STR);
96373c
 }
96373c
 
96373c
-static int
96373c
-set_error(Slapi_PBlock *pb, int retval, int ldap_result_code, char **ldap_result_message)
96373c
-{
96373c
-    int opreturn = 0;
96373c
-    if (!ldap_result_code) {
96373c
-        slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
96373c
-    }
96373c
-    if (!ldap_result_code) {
96373c
-        ldap_result_code = LDAP_OPERATIONS_ERROR;
96373c
-        slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
96373c
-    }
96373c
-    slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
96373c
-    if (!opreturn) {
96373c
-        slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
96373c
-    }
96373c
-    slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
96373c
-
96373c
-    return opreturn;
96373c
-}
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
96373c
index db463c18c..be0db1bd0 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
96373c
@@ -1276,6 +1276,10 @@ replace_entry:
96373c
     }
96373c
 
96373c
     retval = plugin_call_mmr_plugin_postop(pb, NULL,SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN);
96373c
+    if (retval) {
96373c
+        ldbm_set_error(pb, retval, &ldap_result_code, &ldap_result_message);
96373c
+        goto error_return;
96373c
+    }
96373c
 
96373c
 commit_return:
96373c
     /* Release SERIAL LOCK */
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modify.c b/ldap/servers/slapd/back-ldbm/ldbm_modify.c
96373c
index 7ee796fd2..cc4319e5f 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_modify.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modify.c
96373c
@@ -867,6 +867,10 @@ ldbm_back_modify(Slapi_PBlock *pb)
96373c
         goto error_return;
96373c
     }
96373c
     retval = plugin_call_mmr_plugin_postop(pb, NULL,SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN);
96373c
+    if (retval) {
96373c
+        ldbm_set_error(pb, retval, &ldap_result_code, &ldap_result_message);
96373c
+        goto error_return;
96373c
+    }
96373c
 
96373c
     /* Release SERIAL LOCK */
96373c
     retval = dblayer_txn_commit(be, &txn);
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
96373c
index 2c0cb074e..93fb77dc9 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
96373c
@@ -1211,6 +1211,10 @@ ldbm_back_modrdn(Slapi_PBlock *pb)
96373c
         goto error_return;
96373c
     }
96373c
 	retval = plugin_call_mmr_plugin_postop(pb, NULL,SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN);
96373c
+    if (retval) {
96373c
+        ldbm_set_error(pb, retval, &ldap_result_code, &ldap_result_message);
96373c
+        goto error_return;
96373c
+    }
96373c
 
96373c
     /* Release SERIAL LOCK */
96373c
     retval = dblayer_txn_commit(be, &txn);
96373c
diff --git a/ldap/servers/slapd/back-ldbm/misc.c b/ldap/servers/slapd/back-ldbm/misc.c
96373c
index df1afdfb1..c52e58a4a 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/misc.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/misc.c
96373c
@@ -16,6 +16,24 @@
96373c
 
96373c
 #include "back-ldbm.h"
96373c
 
96373c
+void
96373c
+ldbm_set_error(Slapi_PBlock *pb, int retval, int *ldap_result_code, char **ldap_result_message)
96373c
+{
96373c
+    int opreturn = 0;
96373c
+    if (!(*ldap_result_code)) {
96373c
+        slapi_pblock_get(pb, SLAPI_RESULT_CODE, ldap_result_code);
96373c
+    }
96373c
+    if (!(*ldap_result_code)) {
96373c
+        *ldap_result_code = LDAP_OPERATIONS_ERROR;
96373c
+        slapi_pblock_set(pb, SLAPI_RESULT_CODE, ldap_result_code);
96373c
+    }
96373c
+    slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
96373c
+    if (!opreturn) {
96373c
+        slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, *ldap_result_code ? ldap_result_code : &retval);
96373c
+    }
96373c
+    slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, ldap_result_message);
96373c
+}
96373c
+
96373c
 /* Takes a return code supposed to be errno or from lidb
96373c
    which we don't expect to see and prints a handy log message */
96373c
 void
96373c
diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
96373c
index 0cee3df62..da3eef18b 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
96373c
+++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
96373c
@@ -379,6 +379,7 @@ int ldbm_txn_ruv_modify_context(Slapi_PBlock *pb, modify_context *mc);
96373c
 int get_value_from_string(const char *string, char *type, char **value);
96373c
 int get_values_from_string(const char *string, char *type, char ***valuearray);
96373c
 void normalize_dir(char *dir);
96373c
+void ldbm_set_error(Slapi_PBlock *pb, int retval, int *ldap_result_code, char **ldap_result_message);
96373c
 
96373c
 /*
96373c
  * nextid.c
96373c
-- 
96373c
2.13.6
96373c