Welcome! Log In Create A New Profile

Advanced

[nginx] Memcached: protect from too long responses.

Maxim Dounin
July 06, 2020 02:02PM
details: https://hg.nginx.org/nginx/rev/7731c710796f
branches:
changeset: 7674:7731c710796f
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Jul 06 18:36:17 2020 +0300
description:
Memcached: protect from too long responses.

If a memcached response was followed by a correct trailer, and then
the NUL character followed by some extra data - this was accepted by
the trailer checking code. This in turn resulted in ctx->rest underflow
and caused negative size buffer on the next reading from the upstream,
followed by the "negative size buf in writer" alert.

Fix is to always check for too long responses, so a correct trailer cannot
be followed by extra data.

diffstat:

src/http/modules/ngx_http_memcached_module.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r c5840ca2063d -r 7731c710796f src/http/modules/ngx_http_memcached_module.c
--- a/src/http/modules/ngx_http_memcached_module.c Fri Jul 03 16:16:47 2020 +0300
+++ b/src/http/modules/ngx_http_memcached_module.c Mon Jul 06 18:36:17 2020 +0300
@@ -485,10 +485,11 @@ ngx_http_memcached_filter(void *data, ss

if (u->length == (ssize_t) ctx->rest) {

- if (ngx_strncmp(b->last,
+ if (bytes > u->length
+ || ngx_strncmp(b->last,
ngx_http_memcached_end + NGX_HTTP_MEMCACHED_END - ctx->rest,
bytes)
- != 0)
+ != 0)
{
ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
"memcached sent invalid trailer");
@@ -540,7 +541,9 @@ ngx_http_memcached_filter(void *data, ss

last += (size_t) (u->length - NGX_HTTP_MEMCACHED_END);

- if (ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0) {
+ if (bytes > u->length
+ || ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0)
+ {
ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
"memcached sent invalid trailer");

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Memcached: protect from too long responses.

Maxim Dounin 193 July 06, 2020 02:02PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 205
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready