]> git.kaiwu.me - nginx.git/commitdiff
Fixed handling of very long locations (ticket #2435).
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 26 Jan 2023 00:34:44 +0000 (03:34 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 26 Jan 2023 00:34:44 +0000 (03:34 +0300)
Previously, location prefix length in ngx_http_location_tree_node_t was
stored as "u_char", and therefore location prefixes longer than 255 bytes
were handled incorrectly.

Fix is to use "u_short" instead.  With "u_short", prefixes up to 65535 bytes
can be safely used, and this isn't reachable due to NGX_CONF_BUFFER, which
is 4096 bytes.

src/http/ngx_http.c
src/http/ngx_http_core_module.h

index 73c08d593b775e61d96f0849d157f2f40561c47f..5c628849f2edf4973100a809026beed05e132190 100644 (file)
@@ -1130,7 +1130,7 @@ ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations,
     node->auto_redirect = (u_char) ((lq->exact && lq->exact->auto_redirect)
                            || (lq->inclusive && lq->inclusive->auto_redirect));
 
-    node->len = (u_char) len;
+    node->len = (u_short) len;
     ngx_memcpy(node->name, &lq->name->data[prefix], len);
 
     ngx_queue_split(locations, q, &tail);
index 49bbd4aa9529e4166eb201978e17a9ac599640b8..1c56264c67f3aea70774e827e49d675a16ae8702 100644 (file)
@@ -463,8 +463,8 @@ struct ngx_http_location_tree_node_s {
     ngx_http_core_loc_conf_t        *exact;
     ngx_http_core_loc_conf_t        *inclusive;
 
+    u_short                          len;
     u_char                           auto_redirect;
-    u_char                           len;
     u_char                           name[1];
 };