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

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