diff options
author | Pritha Srivastava <prsrivas@redhat.com> | 2018-10-15 12:58:42 +0200 |
---|---|---|
committer | Pritha Srivastava <prsrivas@redhat.com> | 2018-10-26 10:49:47 +0200 |
commit | 37675172fb2b87c580ecc7719bffada6453691d6 (patch) | |
tree | 0705c4cd105b07cc88dabaf6ee5838ac55a38e57 /src/rgw/rgw_rest.h | |
parent | rgw: Fix for buffer overflow in STS op_post(). (diff) | |
download | ceph-37675172fb2b87c580ecc7719bffada6453691d6.tar.xz ceph-37675172fb2b87c580ecc7719bffada6453691d6.zip |
rgw: Refactored rgw_rest_read_all_input() using bufferlist.
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
Diffstat (limited to 'src/rgw/rgw_rest.h')
-rw-r--r-- | src/rgw/rgw_rest.h | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 556d805c7e2..defbed1d4b5 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -25,24 +25,25 @@ extern void rgw_flush_formatter_and_reset(struct req_state *s, extern void rgw_flush_formatter(struct req_state *s, ceph::Formatter *formatter); -extern int rgw_rest_read_all_input(struct req_state *s, char **data, int *plen, - uint64_t max_len, bool allow_chunked=true); +std::tuple<int, bufferlist > rgw_rest_read_all_input(struct req_state *s, + const uint64_t max_len, + const bool allow_chunked=true); template <class T> int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out, uint64_t max_len, bool *empty) { - int rv, data_len; - char *data; - if (empty) *empty = false; - if ((rv = rgw_rest_read_all_input(s, &data, &data_len, max_len)) < 0) { + int rv = 0; + bufferlist data; + std::tie(rv, data) = rgw_rest_read_all_input(s, max_len); + if (rv < 0) { return rv; } - if (!data_len) { + if (!data.length()) { if (empty) { *empty = true; } @@ -52,13 +53,10 @@ int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out, JSONParser parser; - if (!parser.parse(data, data_len)) { - free(data); + if (!parser.parse(data.c_str(), data.length())) { return -EINVAL; } - free(data); - try { decode_json_obj(out, &parser); } catch (JSONDecoder::err& e) { @@ -69,37 +67,32 @@ int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out, } template <class T> -int rgw_rest_get_json_input_keep_data(CephContext *cct, req_state *s, T& out, uint64_t max_len, char **pdata, int *len) +std::tuple<int, bufferlist > rgw_rest_get_json_input_keep_data(CephContext *cct, req_state *s, T& out, uint64_t max_len) { - int rv, data_len; - char *data; - - if ((rv = rgw_rest_read_all_input(s, &data, &data_len, max_len)) < 0) { - return rv; + int rv = 0; + bufferlist data; + std::tie(rv, data) = rgw_rest_read_all_input(s, max_len); + if (rv < 0) { + return std::make_tuple(rv, std::move(data)); } - if (!data_len) { - return -EINVAL; + if (!data.length()) { + return std::make_tuple(-EINVAL, std::move(data)); } - *len = data_len; - JSONParser parser; - if (!parser.parse(data, data_len)) { - free(data); - return -EINVAL; + if (!parser.parse(data.c_str(), data.length())) { + return std::make_tuple(-EINVAL, std::move(data)); } try { decode_json_obj(out, &parser); } catch (JSONDecoder::err& e) { - free(data); - return -EINVAL; + return std::make_tuple(-EINVAL, std::move(data)); } - *pdata = data; - return 0; + return std::make_tuple(0, std::move(data)); } class RESTArgs { |