]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rest_conn: parse_json bails on failed parsing
authorAbhishek Lekshmanan <abhishek@suse.com>
Thu, 18 Apr 2019 11:49:52 +0000 (13:49 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Thu, 18 Apr 2019 11:49:52 +0000 (13:49 +0200)
Currently the json parser parsing errors get ignored while we check the value as
integer reading from a bool. This causes failures in cases when for eg. XML is
supplied to the parser getting ignored and we fail later in the stack with the
default initialized value of T. Also drop the ignored ceph context

Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
src/rgw/rgw_rest_conn.h

index ccc05d007f3dd6886ace7a0384f6b75c08245acf..5bc0728b636d4591aaaaa8df902cc67677f24dd3 100644 (file)
@@ -15,12 +15,11 @@ class CephContext;
 class RGWSI_Zone;
 
 template <class T>
-static int parse_decode_json(CephContext *cct, T& t, bufferlist& bl)
+static int parse_decode_json(T& t, bufferlist& bl)
 {
   JSONParser p;
-  int ret = p.parse(bl.c_str(), bl.length());
-  if (ret < 0) {
-    return ret;
+  if (!p.parse(bl.c_str(), bl.length())) {
+    return -EINVAL;
   }
 
   try {
@@ -216,7 +215,7 @@ int RGWRESTConn::get_json_resource(const string& resource, param_vec_t *params,
     return ret;
   }
 
-  ret = parse_decode_json(cct, t, bl);
+  ret = parse_decode_json(t, bl);
   if (ret < 0) {
     return ret;
   }
@@ -330,7 +329,7 @@ int RGWRESTReadResource::decode_resource(T *dest)
   if (ret < 0) {
     return ret;
   }
-  ret = parse_decode_json(cct, *dest, bl);
+  ret = parse_decode_json(*dest, bl);
   if (ret < 0) {
     return ret;
   }
@@ -449,7 +448,7 @@ int RGWRESTSendResource::decode_resource(T *dest, E *err_result)
   int ret = req.get_status();
   if (ret < 0) {
     if (err_result) {
-      parse_decode_json(cct, *err_result, bl);
+      parse_decode_json(*err_result, bl);
     }
     return ret;
   }
@@ -458,7 +457,7 @@ int RGWRESTSendResource::decode_resource(T *dest, E *err_result)
     return 0;
   }
 
-  ret = parse_decode_json(cct, *dest, bl);
+  ret = parse_decode_json(*dest, bl);
   if (ret < 0) {
     return ret;
   }
@@ -471,7 +470,7 @@ int RGWRESTSendResource::wait(T *dest, optional_yield y, E *err_result)
   int ret = req.wait(y);
   if (ret < 0) {
     if (err_result) {
-      parse_decode_json(cct, *err_result, bl);
+      parse_decode_json(*err_result, bl);
     }
     return ret;
   }