From: Abhishek Lekshmanan Date: Thu, 18 Apr 2019 11:49:52 +0000 (+0200) Subject: rgw: rest_conn: parse_json bails on failed parsing X-Git-Tag: v15.1.0~2709^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2cee0fa3727e827128788407e80ac3181dc41e4a;p=ceph.git rgw: rest_conn: parse_json bails on failed parsing 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 --- diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index ccc05d007f3d..5bc0728b636d 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -15,12 +15,11 @@ class CephContext; class RGWSI_Zone; template -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; }