From: Michael Wallner Date: Wed, 20 Jan 2021 15:39:30 +0000 (+0100) Subject: Fix libmemcachedprotocol's binary `STAT` and `VERSION` handlers. X-Git-Tag: 1.1.0-beta3~17 X-Git-Url: https://git.m6w6.name/?p=awesomized%2Flibmemcached;a=commitdiff_plain;h=2a67d9900d37f4ec3164294fcf95e0efb8a49a64 Fix libmemcachedprotocol's binary `STAT` and `VERSION` handlers. --- diff --git a/ChangeLog-1.1.md b/ChangeLog-1.1.md index d9e8bf5f..02090ca2 100644 --- a/ChangeLog-1.1.md +++ b/ChangeLog-1.1.md @@ -6,6 +6,7 @@ **Changes from beta2:** +* Fix libmemcachedprotocol's binary `STAT` and `VERSION` handlers. * Fix [gh #105](https://github.com/m6w6/libmemcached/issues/105): EINTR handled too defensively when polling. @@ -32,7 +33,7 @@ > released 2020-12-21 -**NOTE:** +**NOTE:** This is a bug fix release, not a feature release. The minor version number was incremented due to the following changes: diff --git a/docs/source/ChangeLog-1.1.rst b/docs/source/ChangeLog-1.1.rst index 9bcdf781..ab6458c9 100644 --- a/docs/source/ChangeLog-1.1.rst +++ b/docs/source/ChangeLog-1.1.rst @@ -16,6 +16,7 @@ v 1.1.0-beta3 **Changes from beta2:** +* Fix libmemcachedprotocol's binary ``STAT`` and ``VERSION`` handlers. * Fix `gh #105 `_\ : EINTR handled too defensively when polling. @@ -51,7 +52,7 @@ v 1.1.0-beta1 released 2020-12-21 -**NOTE:** +**NOTE:**\ :raw-html-m2r:`
` This is a bug fix release, not a feature release. The minor version number was incremented due to the following changes: diff --git a/src/libmemcachedprotocol/binary_handler.c b/src/libmemcachedprotocol/binary_handler.c index a1b072d0..c5419619 100644 --- a/src/libmemcachedprotocol/binary_handler.c +++ b/src/libmemcachedprotocol/binary_handler.c @@ -44,7 +44,7 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header * protocol_binary_response_header *response) { memcached_protocol_client_st *client = (void *) cookie; - if (client->root->pedantic + if (response && client->root->pedantic && !memcached_binary_protocol_pedantic_check_response(request, response)) { return PROTOCOL_BINARY_RESPONSE_EINVAL; } @@ -53,6 +53,10 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header * return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } + if (!response) { + return PROTOCOL_BINARY_RESPONSE_SUCCESS; + } + size_t len = sizeof(protocol_binary_response_header) + htonl(response->response.bodylen); size_t offset = 0; char *ptr = (void *) response; @@ -917,6 +921,20 @@ stat_command_handler(const void *cookie, protocol_binary_request_header *header, rval = client->root->callback->interface.v1.stat(cookie, (void *) (header + 1), keylen, stat_response_handler); + if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { + /* END message */ + protocol_binary_response_no_extras response = { + .message = { + .header.response = + { + .magic = PROTOCOL_BINARY_RES, + .opcode = PROTOCOL_BINARY_CMD_STAT, + .status = htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), + .opaque = header->request.opaque, + }, + }}; + rval = response_handler(cookie, header, &response); + } } else { rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; } @@ -941,6 +959,9 @@ version_command_handler(const void *cookie, protocol_binary_request_header *head memcached_protocol_client_st *client = (void *) cookie; if (client->root->callback->interface.v1.version) { rval = client->root->callback->interface.v1.version(cookie, version_response_handler); + if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { + rval = response_handler(cookie, header, NULL); + } } else { rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; }