]> git.kaiwu.me - nginx.git/commitdiff
Memcached: respect the end marker in the maximum supported length
authorVadim Zhestikov <v.zhestikov@f5.com>
Tue, 11 Aug 2026 18:06:28 +0000 (11:06 -0700)
committerVadimZhestikov <108960056+VadimZhestikov@users.noreply.github.com>
Tue, 25 Aug 2026 21:35:31 +0000 (14:35 -0700)
The length in the "VALUE" line was accepted up to NGX_MAX_OFF_T_VALUE,
while ngx_http_memcached_filter_init() adds the size of the end marker
to it.  With lengths close to the maximum this overflowed u->length.

Now such lengths are rejected, similarly to other invalid lengths.

src/http/modules/ngx_http_memcached_module.c

index 11bbd91659c76fe34592315e895a482d8f04b3d4..178140d2facc63a3936f1efce3dcdd318dd20c89 100644 (file)
@@ -413,7 +413,11 @@ found:
         p = line.data + line.len;
 
         u->headers_in.content_length_n = ngx_atoof(start, p - start);
-        if (u->headers_in.content_length_n == NGX_ERROR) {
+
+        if (u->headers_in.content_length_n == NGX_ERROR
+            || u->headers_in.content_length_n
+               > NGX_MAX_OFF_T_VALUE - (off_t) NGX_HTTP_MEMCACHED_END)
+        {
             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                           "memcached sent invalid length in response \"%V\" "
                           "for key \"%V\"",