Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert needs to use uint64 parser for values #247

Merged
merged 2 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/server/rds/data/cmd_sarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cmd_sarray_create(struct response *rsp, const struct request *req,
item_rstatus_e istatus;
uint32_t ntoken;
bool bounded;
int64_t esize, low, high;
uint64_t esize, low, high;

ntoken = array_nelem(req->token);
ASSERT(ntoken >= cmd->narg);
Expand All @@ -102,7 +102,7 @@ cmd_sarray_create(struct response *rsp, const struct request *req,

return;
}
if (!req_get_int(&esize, req, SARRAY_ESIZE)) {
if (!req_get_uint(&esize, req, SARRAY_ESIZE)) {
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_create_ex);

Expand All @@ -118,8 +118,8 @@ cmd_sarray_create(struct response *rsp, const struct request *req,
}

/* get low & high watermarks */
if (cmd->nopt > 0 && (!req_get_int(&low, req, SARRAY_WML) ||
!req_get_int(&high, req, SARRAY_WMH))) {
if (cmd->nopt > 0 && (!req_get_uint(&low, req, SARRAY_WML) ||
!req_get_uint(&high, req, SARRAY_WMH))) {
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_create_ex);

Expand Down Expand Up @@ -225,7 +225,7 @@ cmd_sarray_find(struct response *rsp, const struct request *req, const struct
struct bstring *key = &null_key;
struct item *it;
uint32_t idx;
int64_t val;
uint64_t val;
sarray_rstatus_e status;

ASSERT(array_nelem(req->token) == cmd->narg);
Expand All @@ -238,7 +238,7 @@ cmd_sarray_find(struct response *rsp, const struct request *req, const struct

return;
}
if (!req_get_int(&val, req, SARRAY_VAL)) {
if (!req_get_uint(&val, req, SARRAY_VAL)) {
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_find_ex);

Expand Down Expand Up @@ -372,7 +372,8 @@ cmd_sarray_insert(struct response *rsp, const struct request *req, const struct
struct bstring *key = &null_key;
struct item *it;
uint32_t nval = 0, esize;
int64_t delta, val, wml, wmh, nentry, ninserted = 0;
int64_t delta, wml, wmh, nentry, ninserted = 0;
uint64_t val;
sarray_p sa;
sarray_rstatus_e status;

Expand All @@ -397,13 +398,14 @@ cmd_sarray_insert(struct response *rsp, const struct request *req, const struct

/* parse and store all values to be inserted in array vals */
for (uint32_t i = SARRAY_VAL; i < array_nelem(req->token); ++i, ++nval) {
if (!req_get_int(&val, req, i)) {
if (!req_get_uint(&val, req, i)) {
log_debug("the value at offset %"PRIu32" is invalid", i);
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_insert_ex);

return;
} else {
vals[nval] = (uint64_t)val;
vals[nval] = val;
}
}

Expand Down Expand Up @@ -442,6 +444,7 @@ cmd_sarray_insert(struct response *rsp, const struct request *req, const struct
for (uint32_t i = 0; i < nval; ++i) {
status = sarray_insert(sa, vals[i]);
if (status == SARRAY_EINVALID) {
log_debug("value %"PRIu32" out of %"PRIu32" is invalid", i, nval);
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_insert_ex);
return;
Expand Down Expand Up @@ -530,6 +533,7 @@ cmd_sarray_remove(struct response *rsp, const struct request *req, const struct
break;
case SARRAY_EINVALID:
/* client error, bad argument */
log_debug("value %"PRIu32" out of %"PRIu32" is invalid", i, nval);
compose_rsp_client_err(rsp, reply, cmd, key);
INCR(process_metrics, sarray_remove_ex);

Expand Down
16 changes: 16 additions & 0 deletions src/server/rds/data/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ req_get_int(int64_t *i, const struct request *req, uint32_t offset)

return true;
}

static inline bool
req_get_uint(uint64_t *u, const struct request *req, uint32_t offset)
{
struct bstring *bstr;

if (!req_get_bstr(&bstr, req, offset)) {
return false;
}

if (bstring_atou64(u, bstr) != CC_OK) {
return false;
}

return true;
}