FAILS ldb/sample_module: don't write to const memory
authorStefan Metzmacher <metze@samba.org>
Wed, 11 Sep 2013 06:31:43 +0000 (08:31 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Sep 2013 22:11:44 +0000 (00:11 +0200)
req->op.add.message is the callers memory and declared as const.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
FAILS: TDB_NO_FSYNC=1 buildnice bin/timelimit 180 make -j test TESTS=ldb.base

lib/ldb/tests/sample_module.c

index bee40a5e80fc105447010631e03c981c486672af..09d1b6ab19a293c97e7b0e6ba6d3073f3de12b6d 100644 (file)
 static int sample_add(struct ldb_module *mod, struct ldb_request *req)
 {
        struct ldb_control *control;
-
-       ldb_msg_add_fmt(req->op.add.message, "touchedBy", "sample");
+       struct ldb_context *ldb = ldb_module_get_ctx(mod);
+       struct ldb_message *msg;
+       struct ldb_request *down_req;
+       int ret;
 
        /* check if there's a relax control */
        control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
-       if (control == NULL) {
-               /* not found go on */
-               return ldb_next_request(mod, req);
-       } else {
+       if (control != NULL) {
                return LDB_ERR_UNWILLING_TO_PERFORM;
        }
+
+       msg = ldb_msg_copy_shallow(req, req->op.add.message);
+       if (msg == NULL) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ldb_msg_add_fmt(msg, "touchedBy", "sample");
+
+       ret = ldb_build_add_req(&down_req, ldb, req,
+                               msg,
+                               req->controls,
+                               NULL, /* callback context */
+                               ldb_op_default_callback,
+                               req);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       talloc_steal(down_req, msg);
+
+       /* go on with the call chain */
+       return ldb_next_request(mod, down_req);
 }
 
 static int sample_modify(struct ldb_module *mod, struct ldb_request *req)