]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add try catch for user policies decode 35849/head
authorwangyunqing <wangyunqing@inspur.com>
Tue, 30 Jun 2020 12:43:12 +0000 (20:43 +0800)
committerwangyunqing <wangyunqing@inspur.com>
Fri, 3 Sep 2021 01:20:36 +0000 (09:20 +0800)
Signed-off-by: wangyunqing <wangyunqing@inspur.com>
src/rgw/rgw_rest_user_policy.cc

index a552f3b2b2a2ed4d2d38ddf5b165ee5757bc8694..86e30a30411c11b21c09ba23f1aa07e89e121e49 100644 (file)
@@ -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<string, string> 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<string, string> 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;