From: Danny Al-Gaaf Date: Sat, 20 Jul 2013 17:00:50 +0000 (+0200) Subject: rgw: change RGWOp::name() to return string instead of char* X-Git-Tag: v0.67-rc1~10^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e91042171939b6bf82a56a1015c5cae792d228ad;p=ceph.git rgw: change RGWOp::name() to return string instead of char* Return 'const string' instead of 'const char *' from RGWOp::name() to avoid the usage of std::string:c_str() to return 'const char *' in some cases in rgw_rest_replica_log.h. Returning result of c_str() from a function is dangerous since the result gets (may) invalid after the related string object gets destroyed or out of scope (which is the case with return). So you may end up with garbage in this case. Related warning from cppcheck: [src/rgw/rgw_rest_replica_log.h:39]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [src/rgw/rgw_rest_replica_log.h:59]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [src/rgw/rgw_rest_replica_log.h:79]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call This should also fix: CID 1049250 (#1 of 1): Wrapper object use after free (WRAPPER_ESCAPE) escape: The internal representation of "s" escapes, but is destroyed when it exits scope. CID 1049251 (#1 of 1): Wrapper object use after free (WRAPPER_ESCAPE) escape: The internal representation of "s" escapes, but is destroyed when it exits scope. CID 1049252 (#1 of 1): Wrapper object use after free (WRAPPER_ESCAPE) escape: The internal representation of "s" escapes, but is destroyed when it exits scope. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 7bca53b5e431..e107b90a1556 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -50,7 +50,7 @@ public: virtual void execute() = 0; virtual void send_response() {} virtual void complete() { send_response(); } - virtual const char *name() = 0; + virtual const string name() = 0; virtual uint32_t op_mask() { return 0; } }; @@ -117,7 +117,7 @@ public: virtual int get_params() = 0; virtual int send_response_data(bufferlist& bl, off_t ofs, off_t len) = 0; - virtual const char *name() { return "get_obj"; } + virtual const string name() { return "get_obj"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -147,7 +147,7 @@ public: virtual bool should_get_stats() { return false; } - virtual const char *name() { return "list_buckets"; } + virtual const string name() { return "list_buckets"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -172,7 +172,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "stat_account"; } + virtual const string name() { return "stat_account"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -204,7 +204,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "list_bucket"; } + virtual const string name() { return "list_bucket"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -215,7 +215,7 @@ public: void execute() {} virtual void send_response() = 0; - virtual const char *name() { return "get_bucket_logging"; } + virtual const string name() { return "get_bucket_logging"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -232,7 +232,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "stat_bucket"; } + virtual const string name() { return "stat_bucket"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -258,7 +258,7 @@ public: } virtual int get_params() { return 0; } virtual void send_response() = 0; - virtual const char *name() { return "create_bucket"; } + virtual const string name() { return "create_bucket"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -275,7 +275,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "delete_bucket"; } + virtual const string name() { return "delete_bucket"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; } }; @@ -319,7 +319,7 @@ public: virtual int get_params() = 0; virtual int get_data(bufferlist& bl) = 0; virtual void send_response() = 0; - virtual const char *name() { return "put_obj"; } + virtual const string name() { return "put_obj"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -361,7 +361,7 @@ public: virtual int get_params() = 0; virtual int get_data(bufferlist& bl) = 0; virtual void send_response() = 0; - virtual const char *name() { return "post_obj"; } + virtual const string name() { return "post_obj"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -389,7 +389,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "put_obj_metadata"; } + virtual const string name() { return "put_obj_metadata"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -404,7 +404,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "delete_obj"; } + virtual const string name() { return "delete_obj"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; } }; @@ -472,7 +472,7 @@ public: virtual int init_dest_policy() { return 0; } virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "copy_obj"; } + virtual const string name() { return "copy_obj"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -488,7 +488,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "get_acls"; } + virtual const string name() { return "get_acls"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -514,7 +514,7 @@ public: virtual int get_policy_from_state(RGWRados *store, struct req_state *s, stringstream& ss) { return 0; } virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "put_acls"; } + virtual const string name() { return "put_acls"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -530,7 +530,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "get_cors"; } + virtual const string name() { return "get_cors"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -555,7 +555,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "put_cors"; } + virtual const string name() { return "put_cors"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -570,7 +570,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "delete_cors"; } + virtual const string name() { return "delete_cors"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -590,7 +590,7 @@ public: void execute(); void get_response_params(string& allowed_hdrs, string& exp_hdrs, unsigned *max_age); virtual void send_response() = 0; - virtual const char *name() { return "options_cors"; } + virtual const string name() { return "options_cors"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -614,7 +614,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "init_multipart"; } + virtual const string name() { return "init_multipart"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -643,7 +643,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "complete_multipart"; } + virtual const string name() { return "complete_multipart"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; @@ -658,7 +658,7 @@ public: void execute(); virtual void send_response() = 0; - virtual const char *name() { return "abort_multipart"; } + virtual const string name() { return "abort_multipart"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; } }; @@ -687,7 +687,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "list_multipart"; } + virtual const string name() { return "list_multipart"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -790,7 +790,7 @@ public: virtual int get_params() = 0; virtual void send_response() = 0; - virtual const char *name() { return "list_bucket_multiparts"; } + virtual const string name() { return "list_bucket_multiparts"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; @@ -823,7 +823,7 @@ public: virtual void begin_response() = 0; virtual void send_partial_response(pair& result) = 0; virtual void end_response() = 0; - virtual const char *name() { return "multi_object_delete"; } + virtual const string name() { return "multi_object_delete"; } virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; } }; diff --git a/src/rgw/rgw_rest_bucket.cc b/src/rgw/rgw_rest_bucket.cc index 80b5b876916f..e7068b43c49b 100644 --- a/src/rgw/rgw_rest_bucket.cc +++ b/src/rgw/rgw_rest_bucket.cc @@ -17,7 +17,7 @@ public: void execute(); - virtual const char *name() { return "get_bucket_info"; } + virtual const string name() { return "get_bucket_info"; } }; void RGWOp_Bucket_Info::execute() @@ -52,7 +52,7 @@ public: void execute(); - virtual const char *name() { return "get_policy"; } + virtual const string name() { return "get_policy"; } }; void RGWOp_Get_Policy::execute() @@ -82,7 +82,7 @@ public: void execute(); - virtual const char *name() { return "check_bucket_index"; } + virtual const string name() { return "check_bucket_index"; } }; void RGWOp_Check_Bucket_Index::execute() @@ -116,7 +116,7 @@ public: void execute(); - virtual const char *name() { return "link_bucket"; } + virtual const string name() { return "link_bucket"; } }; void RGWOp_Bucket_Link::execute() @@ -146,7 +146,7 @@ public: void execute(); - virtual const char *name() { return "unlink_bucket"; } + virtual const string name() { return "unlink_bucket"; } }; void RGWOp_Bucket_Unlink::execute() @@ -176,7 +176,7 @@ public: void execute(); - virtual const char *name() { return "remove_bucket"; } + virtual const string name() { return "remove_bucket"; } }; void RGWOp_Bucket_Remove::execute() @@ -206,7 +206,7 @@ public: void execute(); - virtual const char *name() { return "remove_object"; } + virtual const string name() { return "remove_object"; } }; void RGWOp_Object_Remove::execute() diff --git a/src/rgw/rgw_rest_config.h b/src/rgw/rgw_rest_config.h index cb1712ac3d78..2e0408afb3d0 100644 --- a/src/rgw/rgw_rest_config.h +++ b/src/rgw/rgw_rest_config.h @@ -25,7 +25,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "get_region_map"; } }; diff --git a/src/rgw/rgw_rest_log.h b/src/rgw/rgw_rest_log.h index 38c6b5fb4abf..2d60e289b84a 100644 --- a/src/rgw/rgw_rest_log.h +++ b/src/rgw/rgw_rest_log.h @@ -32,7 +32,7 @@ public: virtual void send_response(list& entries, string& marker); virtual void send_response_end(); void execute(); - virtual const char *name() { + virtual const string name() { return "list_bucket_index_log"; } }; @@ -53,7 +53,7 @@ public: } virtual void send_response(); void execute(); - virtual const char *name() { + virtual const string name() { return "bucket_index_log_info"; } }; @@ -67,7 +67,7 @@ public: return caps.check_cap("bilog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "trim_bucket_index_log"; } }; @@ -87,7 +87,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "list_metadata_log"; } }; @@ -107,7 +107,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "get_metadata_log_info"; } }; @@ -126,7 +126,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "get_metadata_log_shard_info"; } }; @@ -140,7 +140,7 @@ public: return caps.check_cap("mdlog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "lock_mdlog_object"; } }; @@ -154,7 +154,7 @@ public: return caps.check_cap("mdlog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "unlock_mdlog_object"; } }; @@ -168,7 +168,7 @@ public: return caps.check_cap("mdlog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "trim_metadata_log"; } }; @@ -188,7 +188,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "list_data_changes_log"; } }; @@ -208,7 +208,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "get_data_changes_log_info"; } }; @@ -227,7 +227,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "get_data_changes_log_shard_info"; } }; @@ -241,7 +241,7 @@ public: return caps.check_cap("datalog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "lock_datalog_object"; } }; @@ -255,7 +255,7 @@ public: return caps.check_cap("datalog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "unlock_datalog_object"; } }; @@ -269,7 +269,7 @@ public: return caps.check_cap("datalog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "trim_data_changes_log"; } }; diff --git a/src/rgw/rgw_rest_metadata.cc b/src/rgw/rgw_rest_metadata.cc index 69f8a5ccbc45..35ec0ab9b04f 100644 --- a/src/rgw/rgw_rest_metadata.cc +++ b/src/rgw/rgw_rest_metadata.cc @@ -23,7 +23,7 @@ #define dout_subsys ceph_subsys_rgw -const char *RGWOp_Metadata_Get::name() { +const string RGWOp_Metadata_Get::name() { return "get_metadata"; } @@ -62,7 +62,7 @@ void RGWOp_Metadata_Get::execute() { http_ret = 0; } -const char *RGWOp_Metadata_List::name() { +const string RGWOp_Metadata_List::name() { return "list_metadata"; } diff --git a/src/rgw/rgw_rest_metadata.h b/src/rgw/rgw_rest_metadata.h index 85993d08d587..59d7c5f70455 100644 --- a/src/rgw/rgw_rest_metadata.h +++ b/src/rgw/rgw_rest_metadata.h @@ -23,7 +23,7 @@ public: return caps.check_cap("metadata", RGW_CAP_READ); } void execute(); - virtual const char *name(); + virtual const string name(); }; class RGWOp_Metadata_Get : public RGWRESTOp { @@ -35,7 +35,7 @@ public: return caps.check_cap("metadata", RGW_CAP_READ); } void execute(); - virtual const char *name(); + virtual const string name(); }; class RGWOp_Metadata_Put : public RGWRESTOp { @@ -48,7 +48,7 @@ public: return caps.check_cap("metadata", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { return "set_metadata"; } + virtual const string name() { return "set_metadata"; } }; class RGWOp_Metadata_Delete : public RGWRESTOp { @@ -60,7 +60,7 @@ public: return caps.check_cap("metadata", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { return "remove_metadata"; } + virtual const string name() { return "remove_metadata"; } }; class RGWOp_Metadata_Lock : public RGWRESTOp { @@ -72,7 +72,7 @@ public: return caps.check_cap("metadata", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "lock_metadata_object"; } }; @@ -86,7 +86,7 @@ public: return caps.check_cap("metadata", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "unlock_metadata_object"; } }; diff --git a/src/rgw/rgw_rest_opstate.h b/src/rgw/rgw_rest_opstate.h index 8f6a9675a68d..de13dde6966b 100644 --- a/src/rgw/rgw_rest_opstate.h +++ b/src/rgw/rgw_rest_opstate.h @@ -30,7 +30,7 @@ public: virtual void send_response(); virtual void send_response(list entries); virtual void send_response_end(); - virtual const char *name() { + virtual const string name() { return "opstate_list"; } }; @@ -44,7 +44,7 @@ public: return caps.check_cap("opstate", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "set_opstate"; } }; @@ -58,7 +58,7 @@ public: return caps.check_cap("opstate", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "renew_opstate"; } }; @@ -72,7 +72,7 @@ public: return caps.check_cap("opstate", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "delete_opstate"; } }; diff --git a/src/rgw/rgw_rest_replica_log.h b/src/rgw/rgw_rest_replica_log.h index 91e3d6140629..c879150cc07e 100644 --- a/src/rgw/rgw_rest_replica_log.h +++ b/src/rgw/rgw_rest_replica_log.h @@ -32,11 +32,11 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { string s = "replica"; s.append(obj_type); s.append("_getbounds"); - return s.c_str(); + return s; } }; @@ -52,11 +52,11 @@ public: return caps.check_cap(obj_type.c_str(), RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { string s = "replica"; s.append(obj_type); s.append("_updatebounds"); - return s.c_str(); + return s; } }; @@ -72,11 +72,11 @@ public: return caps.check_cap(obj_type.c_str(), RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { string s = "replica"; s.append(obj_type); s.append("_deletebound"); - return s.c_str(); + return s; } }; @@ -94,7 +94,7 @@ public: } void execute(); virtual void send_response(); - virtual const char *name() { + virtual const string name() { return "replicabilog_getbounds"; } }; @@ -108,7 +108,7 @@ public: return caps.check_cap("bilog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "replicabilog_updatebounds"; } }; @@ -122,7 +122,7 @@ public: return caps.check_cap("bilog", RGW_CAP_WRITE); } void execute(); - virtual const char *name() { + virtual const string name() { return "replicabilog_deletebound"; } }; diff --git a/src/rgw/rgw_rest_usage.cc b/src/rgw/rgw_rest_usage.cc index 769e167019a5..1124d2b298b3 100644 --- a/src/rgw/rgw_rest_usage.cc +++ b/src/rgw/rgw_rest_usage.cc @@ -16,7 +16,7 @@ public: } void execute(); - virtual const char *name() { return "get_usage"; } + virtual const string name() { return "get_usage"; } }; void RGWOp_Usage_Get::execute() { @@ -58,7 +58,7 @@ public: } void execute(); - virtual const char *name() { return "trim_usage"; } + virtual const string name() { return "trim_usage"; } }; void RGWOp_Usage_Delete::execute() { diff --git a/src/rgw/rgw_rest_user.cc b/src/rgw/rgw_rest_user.cc index ac0d794846c2..3d08e4032295 100644 --- a/src/rgw/rgw_rest_user.cc +++ b/src/rgw/rgw_rest_user.cc @@ -17,7 +17,7 @@ public: void execute(); - virtual const char *name() { return "get_user_info"; } + virtual const string name() { return "get_user_info"; } }; void RGWOp_User_Info::execute() @@ -44,7 +44,7 @@ public: void execute(); - virtual const char *name() { return "create_user"; } + virtual const string name() { return "create_user"; } }; void RGWOp_User_Create::execute() @@ -138,7 +138,7 @@ public: void execute(); - virtual const char *name() { return "modify_user"; } + virtual const string name() { return "modify_user"; } }; void RGWOp_User_Modify::execute() @@ -232,7 +232,7 @@ public: void execute(); - virtual const char *name() { return "remove_user"; } + virtual const string name() { return "remove_user"; } }; void RGWOp_User_Remove::execute() @@ -265,7 +265,7 @@ public: void execute(); - virtual const char *name() { return "create_subuser"; } + virtual const string name() { return "create_subuser"; } }; void RGWOp_Subuser_Create::execute() @@ -334,7 +334,7 @@ public: void execute(); - virtual const char *name() { return "modify_subuser"; } + virtual const string name() { return "modify_subuser"; } }; void RGWOp_Subuser_Modify::execute() @@ -399,7 +399,7 @@ public: void execute(); - virtual const char *name() { return "remove_subuser"; } + virtual const string name() { return "remove_subuser"; } }; void RGWOp_Subuser_Remove::execute() @@ -438,7 +438,7 @@ public: void execute(); - virtual const char *name() { return "create_access_key"; } + virtual const string name() { return "create_access_key"; } }; void RGWOp_Key_Create::execute() @@ -500,7 +500,7 @@ public: void execute(); - virtual const char *name() { return "remove_access_key"; } + virtual const string name() { return "remove_access_key"; } }; void RGWOp_Key_Remove::execute() @@ -552,7 +552,7 @@ public: void execute(); - virtual const char *name() { return "add_user_caps"; } + virtual const string name() { return "add_user_caps"; } }; void RGWOp_Caps_Add::execute() @@ -586,7 +586,7 @@ public: void execute(); - virtual const char *name() { return "remove_user_caps"; } + virtual const string name() { return "remove_user_caps"; } }; void RGWOp_Caps_Remove::execute() diff --git a/src/rgw/rgw_swift_auth.h b/src/rgw/rgw_swift_auth.h index 8a58b4764965..670a339210d9 100644 --- a/src/rgw/rgw_swift_auth.h +++ b/src/rgw/rgw_swift_auth.h @@ -15,7 +15,7 @@ public: int verify_permission() { return 0; } void execute(); - virtual const char *name() { return "swift_auth_get"; } + virtual const string name() { return "swift_auth_get"; } }; class RGWHandler_SWIFT_Auth : public RGWHandler {