]> git.kaiwu.me - nginx.git/commitdiff
Rejected zero size in buffer-size directives
authorSourav Bhowmik <s.bhowmik@f5.com>
Thu, 13 Aug 2026 12:40:29 +0000 (05:40 -0700)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 25 Sep 2026 18:27:38 +0000 (22:27 +0400)
When set to zero, this resulted in a buffer with no room to read into.
As there is no meaningful interpretation of a zero-sized buffer, such
configuration is explicitly rejected.

Reported by kh-lee

16 files changed:
src/core/ngx_conf_file.c
src/core/ngx_conf_file.h
src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_grpc_module.c
src/http/modules/ngx_http_memcached_module.c
src/http/modules/ngx_http_mp4_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/modules/ngx_http_scgi_module.c
src/http/modules/ngx_http_ssl_module.c
src/http/modules/ngx_http_tunnel_module.c
src/http/modules/ngx_http_uwsgi_module.c
src/http/ngx_http_core_module.c
src/http/v3/ngx_http_v3_module.c
src/mail/ngx_mail_proxy_module.c
src/stream/ngx_stream_core_module.c
src/stream/ngx_stream_proxy_module.c

index 5aee80146c38406cd4d07947554c5a0c3a262637..bc902d273873cb722b0df3b4d7d7e6912769c9cc 100644 (file)
@@ -59,6 +59,9 @@ static ngx_uint_t argument_number[] = {
 };
 
 
+ngx_conf_post_t  ngx_conf_size_nonzero_post = { ngx_conf_check_size_nonzero };
+
+
 char *
 ngx_conf_param(ngx_conf_t *cf)
 {
@@ -1487,3 +1490,16 @@ ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data)
 
     return NGX_CONF_ERROR;
 }
+
+
+char *
+ngx_conf_check_size_nonzero(ngx_conf_t *cf, void *post, void *data)
+{
+    size_t  *sp = data;
+
+    if (*sp == 0) {
+        return "value must be nonzero";
+    }
+
+    return NGX_CONF_OK;
+}
index ed2d2ba9d6922025affd79be1e4033f6f36e603a..b507fbb280928b588f1b5025b778aed3ef22b713 100644 (file)
@@ -171,6 +171,10 @@ typedef struct {
 
 char * ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data);
 char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data);
+char *ngx_conf_check_size_nonzero(ngx_conf_t *cf, void *post, void *data);
+
+
+extern ngx_conf_post_t  ngx_conf_size_nonzero_post;
 
 
 #define ngx_get_conf(conf_ctx, module)  conf_ctx[module.index]
index 7e8953ab15e9b28b0d967c72292a1c396a3bc991..aad2beb650990021ce7ffc304d719b2f9e82efac 100644 (file)
@@ -336,7 +336,7 @@ static ngx_command_t  ngx_http_fastcgi_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("fastcgi_pass_request_headers"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
index ab68b46ee58678238ed03aeac4962c4be6c35a63..ec9101b3fab62acf745e8772d2b782a540fcc493 100644 (file)
@@ -317,7 +317,7 @@ static ngx_command_t  ngx_http_grpc_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_grpc_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("grpc_read_timeout"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
index 178140d2facc63a3936f1efce3dcdd318dd20c89..e7e8871ae698dc4a38dc0ab59b86fd8086803b64 100644 (file)
@@ -93,7 +93,7 @@ static ngx_command_t  ngx_http_memcached_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_memcached_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("memcached_read_timeout"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
index 0ccdf135a58ad3d1692ef95373486c6a7e3aa3db..65845ff7682182c565b0d6092751d05f061d9f41 100644 (file)
@@ -374,14 +374,14 @@ static ngx_command_t  ngx_http_mp4_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_mp4_conf_t, buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("mp4_max_buffer_size"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_mp4_conf_t, max_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("mp4_start_key_frame"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
index 28c530ac317337295d1875bbc42c30b32abbe6cd..99b915c52d2f6c56967b65206e749bb9f13968f6 100644 (file)
@@ -394,7 +394,7 @@ static ngx_command_t  ngx_http_proxy_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_proxy_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("proxy_read_timeout"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
index fd0907c13d95e81535e239226d80b8d07c6d6d87..95fb7462b8fd7d20236207b3189695ef88835fcf 100644 (file)
@@ -184,7 +184,7 @@ static ngx_command_t ngx_http_scgi_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_scgi_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("scgi_pass_request_headers"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
index 286058fbe398fbeb850d8b9223fb3a2b9fa123f5..f4cb6765deba95493098c648e3a0ccf69a6f7408 100644 (file)
@@ -171,7 +171,7 @@ static ngx_command_t  ngx_http_ssl_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_ssl_srv_conf_t, buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("ssl_verify_client"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
index ddffebbcaaeb05b0fbf72f0079e6ce78ed6ee0ba..d35052e7f7f6956cebdf9fead65780e75a43e932 100644 (file)
@@ -113,7 +113,7 @@ static ngx_command_t  ngx_http_tunnel_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_tunnel_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("tunnel_read_timeout"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
index 6193c941e21af5049ffb8dd2167e8bb811caaa86..1b7286f505728701d9b864a66a1048433e19ea9f 100644 (file)
@@ -252,7 +252,7 @@ static ngx_command_t ngx_http_uwsgi_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_uwsgi_loc_conf_t, upstream.buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("uwsgi_pass_request_headers"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
index 7aa96206f94077bddafe5d1679b6d4d6134b4646..380ee21b293165a35a9d39bc4d51b7812c0838aa 100644 (file)
@@ -243,7 +243,7 @@ static ngx_command_t  ngx_http_core_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("large_client_header_buffers"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
@@ -364,7 +364,7 @@ static ngx_command_t  ngx_http_core_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("client_body_timeout"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
@@ -421,7 +421,7 @@ static ngx_command_t  ngx_http_core_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_core_loc_conf_t, subrequest_output_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("aio"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
index 139bd65f3d9a08641fbb6802de47eba0c4bf1553..9e5dc4cac6a8b42409711d32333cd397e346534a 100644 (file)
@@ -48,7 +48,7 @@ static ngx_command_t  ngx_http_v3_commands[] = {
       ngx_conf_set_size_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_v3_srv_conf_t, quic.stream_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("quic_retry"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
index f42c9e2a1a51a8b1e75ee6993f3745a57179ef97..4ecc95ea061a8f52e9ece6c9e74433e1b7329ee1 100644 (file)
@@ -62,7 +62,7 @@ static ngx_command_t  ngx_mail_proxy_commands[] = {
       ngx_conf_set_size_slot,
       NGX_MAIL_SRV_CONF_OFFSET,
       offsetof(ngx_mail_proxy_conf_t, buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("proxy_timeout"),
       NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
index 6556c5a73cffa7cbeea577e655cd9a33f3f85135..11abd9fc23a6cce7425c9ad4b336e02efd75a865 100644 (file)
@@ -124,7 +124,7 @@ static ngx_command_t  ngx_stream_core_commands[] = {
       ngx_conf_set_size_slot,
       NGX_STREAM_SRV_CONF_OFFSET,
       offsetof(ngx_stream_core_srv_conf_t, preread_buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("preread_timeout"),
       NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
index 3f896a116c443aeb5da2141b07f7913e4ce9ea9b..e8c71b7b21c027280e07690e0ae8f015b4ab8983 100644 (file)
@@ -209,7 +209,7 @@ static ngx_command_t  ngx_stream_proxy_commands[] = {
       ngx_conf_set_size_slot,
       NGX_STREAM_SRV_CONF_OFFSET,
       offsetof(ngx_stream_proxy_srv_conf_t, buffer_size),
-      NULL },
+      &ngx_conf_size_nonzero_post },
 
     { ngx_string("proxy_downstream_buffer"),
       NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,