From: wangyunqing Date: Tue, 30 Jun 2020 12:43:12 +0000 (+0800) Subject: rgw: add try catch for user policies decode X-Git-Tag: v18.0.0~1471^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=870b0292352f62e7ab714a00b71262df2ec8cae8;p=ceph.git rgw: add try catch for user policies decode Signed-off-by: wangyunqing --- diff --git a/src/rgw/rgw_rest_user_policy.cc b/src/rgw/rgw_rest_user_policy.cc index a552f3b2b2a..86e30a30411 100644 --- a/src/rgw/rgw_rest_user_policy.cc +++ b/src/rgw/rgw_rest_user_policy.cc @@ -156,6 +156,9 @@ void RGWPutUserPolicy::execute(optional_yield y) if (op_ret < 0) { op_ret = -ERR_INTERNAL_ERROR; } + } catch (buffer::error& err) { + ldpp_dout(this, 0) << "ERROR: failed to decode user policies" << dendl; + op_ret = -EIO; } catch (rgw::IAM::PolicyParseException& e) { ldpp_dout(this, 20) << "failed to parse policy: " << e.what() << dendl; op_ret = -ERR_MALFORMED_DOC; @@ -213,7 +216,13 @@ void RGWGetUserPolicy::execute(optional_yield y) map policies; if (auto it = user->get_attrs().find(RGW_ATTR_USER_POLICY); it != user->get_attrs().end()) { bufferlist bl = it->second; - decode(policies, bl); + try { + decode(policies, bl); + } catch (buffer::error& err) { + ldpp_dout(this, 0) << "ERROR: failed to decode user policies" << dendl; + op_ret = -EIO; + return; + } if (auto it = policies.find(policy_name); it != policies.end()) { policy = policies[policy_name]; dump(s->formatter); @@ -276,7 +285,13 @@ void RGWListUserPolicies::execute(optional_yield y) s->formatter->close_section(); s->formatter->open_object_section("ListUserPoliciesResult"); bufferlist bl = it->second; - decode(policies, bl); + try { + decode(policies, bl); + } catch (buffer::error& err) { + ldpp_dout(this, 0) << "ERROR: failed to decode user policies" << dendl; + op_ret = -EIO; + return; + } for (const auto& p : policies) { s->formatter->open_object_section("PolicyNames"); s->formatter->dump_string("member", p.first); @@ -348,7 +363,13 @@ void RGWDeleteUserPolicy::execute(optional_yield y) map policies; if (auto it = user->get_attrs().find(RGW_ATTR_USER_POLICY); it != user->get_attrs().end()) { bufferlist out_bl = it->second; - decode(policies, out_bl); + try { + decode(policies, out_bl); + } catch (buffer::error& err) { + ldpp_dout(this, 0) << "ERROR: failed to decode user policies" << dendl; + op_ret = -EIO; + return; + } if (auto p = policies.find(policy_name); p != policies.end()) { bufferlist in_bl;