Skip to content

Commit

Permalink
FIX: Modify mismatched error types when get_item_info failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ing-eoking committed Mar 5, 2024
1 parent 5505624 commit 6a0b22a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -3212,17 +3212,13 @@ static void complete_update_ascii(conn *c)
}

item *it = c->item;
ENGINE_ERROR_CODE ret;
if (!mc_engine.v1->get_item_info(mc_engine.v0, c, it, &c->hinfo)) {
mc_engine.v1->release(mc_engine.v0, c, it);
mc_logger->log(EXTENSION_LOG_WARNING, c,
"%d: Failed to get item info\n", c->sfd);
out_string(c, "SERVER_ERROR failed to get item details");
ret = ENGINE_ENOMEM;
return;
}

ENGINE_ERROR_CODE ret;
if (hinfo_check_ascii_tail_string(&c->hinfo) != 0) { /* check "\r\n" */
out_string(c, "CLIENT_ERROR bad data chunk");
} else if (hinfo_check_ascii_tail_string(&c->hinfo) != 0) { /* check "\r\n" */
ret = ENGINE_EBADVALUE;
} else {
ret = mc_engine.v1->store(mc_engine.v0, c, it, &c->cas, c->store_op, 0);
Expand Down Expand Up @@ -3254,7 +3250,7 @@ static void complete_update_ascii(conn *c)
break;
}
#endif

}
switch (ret) {
case ENGINE_SUCCESS:
out_string(c, "STORED");
Expand Down Expand Up @@ -3292,6 +3288,9 @@ static void complete_update_ascii(conn *c)
case ENGINE_FAILED:
out_string(c, "SERVER_ERROR failure");
break;
case ENGINE_EBADVALUE:
out_string(c, "CLIENT_ERROR bad data chunk");
break;
default:
handle_unexpected_errorcode_ascii(c, __func__, ret);
}
Expand Down Expand Up @@ -3709,7 +3708,7 @@ static void complete_update_bin(conn *c)
mc_engine.v1->release(mc_engine.v0, c, it);
mc_logger->log(EXTENSION_LOG_WARNING, c,
"%d: Failed to get item info\n", c->sfd);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_EINTERNAL, 0);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
return;
}
/* We don't actually receive the trailing two characters in the bin
Expand Down Expand Up @@ -3829,7 +3828,7 @@ static void process_bin_get(conn *c)
mc_engine.v1->release(mc_engine.v0, c, it);
mc_logger->log(EXTENSION_LOG_WARNING, c,
"%d: Failed to get item info\n", c->sfd);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_EINTERNAL, 0);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
break;
}

Expand Down Expand Up @@ -7107,7 +7106,7 @@ static void process_bin_update(conn *c)
if (ret == ENGINE_SUCCESS && !mc_engine.v1->get_item_info(mc_engine.v0,
c, it, &c->hinfo)) {
mc_engine.v1->release(mc_engine.v0, c, it);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_EINTERNAL, 0);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
return;
}

Expand Down Expand Up @@ -7189,7 +7188,7 @@ static void process_bin_append_prepend(conn *c)
if (ret == ENGINE_SUCCESS && !mc_engine.v1->get_item_info(mc_engine.v0,
c, it, &c->hinfo)) {
mc_engine.v1->release(mc_engine.v0, c, it);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_EINTERNAL, 0);
write_bin_packet(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
return;
}

Expand Down Expand Up @@ -8474,8 +8473,7 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
if (ret == ENGINE_SUCCESS) {
if (!mc_engine.v1->get_item_info(mc_engine.v0, c, it, &c->hinfo)) {
mc_engine.v1->release(mc_engine.v0, c, it);
out_string(c, "SERVER_ERROR error getting item data");
ret = ENGINE_FAILED; /* FIXME: error type */
ret = ENGINE_ENOMEM; /* FIXME: error type */
} else {
c->item = it;
ritem_set_first(c, CONN_RTYPE_HINFO, vlen);
Expand All @@ -8488,8 +8486,6 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
out_string(c, "CLIENT_ERROR object too large for cache");
} else if (ret == ENGINE_ENOMEM) {
out_string(c, "SERVER_ERROR out of memory storing object");
} else if (ret == ENGINE_FAILED) {
/* out_string() was called above. so, do nothing */
} else {
handle_unexpected_errorcode_ascii(c, __func__, ret);
}
Expand Down

0 comments on commit 6a0b22a

Please sign in to comment.