From ea47fabf55e2bc9192ddc27f52486b4e58d5e007 Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Fri, 19 Jun 2026 22:54:19 +0300 Subject: [PATCH] Script: simplified copy capture codes. Signed-off-by: Roman Arutyunyan Origin: --- src/http/ngx_http_script.c | 22 ++++++++++++---------- src/stream/ngx_stream_script.c | 10 +++++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c index 8a28e23a6..6b33d01dd 100644 --- a/src/http/ngx_http_script.c +++ b/src/http/ngx_http_script.c @@ -1343,6 +1343,7 @@ ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) { int *cap; u_char *p; + size_t len; ngx_uint_t n; ngx_http_request_t *r; ngx_http_script_copy_capture_code_t *code; @@ -1358,17 +1359,17 @@ ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) if (n < r->ncaptures) { cap = r->captures; + len = cap[n + 1] - cap[n]; if ((e->is_args || e->quote) && (e->request->quoted_uri || e->request->plus_in_uri)) { - p = r->captures_data; + p = r->captures_data + cap[n]; + + return len + 2 * ngx_escape_uri(NULL, p, len, NGX_ESCAPE_ARGS); - return cap[n + 1] - cap[n] - + 2 * ngx_escape_uri(NULL, &p[cap[n]], cap[n + 1] - cap[n], - NGX_ESCAPE_ARGS); } else { - return cap[n + 1] - cap[n]; + return len; } } @@ -1381,6 +1382,7 @@ ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) { int *cap; u_char *p, *pos; + size_t len; ngx_uint_t n; ngx_http_request_t *r; ngx_http_script_copy_capture_code_t *code; @@ -1398,16 +1400,16 @@ ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) if (n < r->ncaptures) { cap = r->captures; - p = r->captures_data; + len = cap[n + 1] - cap[n]; + p = r->captures_data + cap[n]; if ((e->is_args || e->quote) && (e->request->quoted_uri || e->request->plus_in_uri)) { - e->pos = (u_char *) ngx_escape_uri(pos, &p[cap[n]], - cap[n + 1] - cap[n], - NGX_ESCAPE_ARGS); + e->pos = (u_char *) ngx_escape_uri(pos, p, len, NGX_ESCAPE_ARGS); + } else { - e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]); + e->pos = ngx_copy(pos, p, len); } } diff --git a/src/stream/ngx_stream_script.c b/src/stream/ngx_stream_script.c index c447e152f..2cd8b08c7 100644 --- a/src/stream/ngx_stream_script.c +++ b/src/stream/ngx_stream_script.c @@ -894,6 +894,7 @@ size_t ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e) { int *cap; + size_t len; ngx_uint_t n; ngx_stream_session_t *s; ngx_stream_script_copy_capture_code_t *code; @@ -908,7 +909,8 @@ ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e) if (n < s->ncaptures) { cap = s->captures; - return cap[n + 1] - cap[n]; + len = cap[n + 1] - cap[n]; + return len; } return 0; @@ -920,6 +922,7 @@ ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e) { int *cap; u_char *p, *pos; + size_t len; ngx_uint_t n; ngx_stream_session_t *s; ngx_stream_script_copy_capture_code_t *code; @@ -936,8 +939,9 @@ ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e) if (n < s->ncaptures) { cap = s->captures; - p = s->captures_data; - e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]); + len = cap[n + 1] - cap[n]; + p = s->captures_data + cap[n]; + e->pos = ngx_copy(pos, p, len); } ngx_log_debug2(NGX_LOG_DEBUG_STREAM, e->session->connection->log, 0, -- 2.47.3