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

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