From: Soumya Koduri Date: Mon, 3 Jan 2022 07:26:31 +0000 (+0530) Subject: rgw/dbstore: Fix null ptr reference X-Git-Tag: v17.1.0~47^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1c2a7884fa9ba53080db1213ddbd5c495cb906c5;p=ceph.git rgw/dbstore: Fix null ptr reference Initialize Object state once and use the same for all its references. Also fixed a bug in SQLGetLC::prepare() Signed-off-by: Soumya Koduri --- diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index cddea7d8ab9..67707840475 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -565,9 +565,7 @@ namespace rgw::sal { int DBObject::get_obj_state(const DoutPrefixProvider* dpp, RGWObjectCtx* rctx, RGWObjState **state, optional_yield y, bool follow_olh) { - if (!*state) { - *state = new RGWObjState(); - } + *state = &(this->state); DB::Object op_target(store->getDB(), get_bucket()->get_info(), get_obj()); return op_target.get_obj_state(dpp, get_bucket()->get_info(), get_obj(), follow_olh, state); } diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index 02d622a0682..aaf3aa2304e 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -438,7 +438,7 @@ protected: /* XXX: to be removed. Till Dan's patch comes, a placeholder * for RGWObjState */ - RGWObjState* state; + RGWObjState state; public: struct DBReadOp : public ReadOp { @@ -475,13 +475,13 @@ protected: DBObject(DBStore *_st, const rgw_obj_key& _k) : Object(_k), store(_st), - acls() { - } + acls() {} + DBObject(DBStore *_st, const rgw_obj_key& _k, Bucket* _b) : Object(_k, _b), store(_st), - acls() { - } + acls() {} + DBObject(DBObject& _o) = default; virtual int delete_object(const DoutPrefixProvider* dpp, diff --git a/src/rgw/store/dbstore/sqlite/sqliteDB.cc b/src/rgw/store/dbstore/sqlite/sqliteDB.cc index 67cd885adad..a7979b392d5 100644 --- a/src/rgw/store/dbstore/sqlite/sqliteDB.cc +++ b/src/rgw/store/dbstore/sqlite/sqliteDB.cc @@ -2669,10 +2669,10 @@ int SQLGetLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params } else { pstmt = &stmt; } - SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.index.c_str(), sdb); + SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.lc_entry.index.c_str(), sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.index.c_str(), sdb); - SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.bucket_name.c_str(), sdb); + SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.lc_entry.bucket_name.c_str(), sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.entry.bucket.c_str(), sdb); out: