[PATCH 04 of 10] HTTP/2: modified ngx_http_v2_send_chain() loop to be safer
Maxim Dounin
mdounin at mdounin.ru
Tue Nov 24 00:27:07 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1795479772 -10800
# Tue Nov 24 03:22:52 2026 +0300
# Node ID e1b8bf142baffa8dd81f11e47d654f63be405bdf
# Parent f0af3674e99a92f62b3526ed4bf3df762f422323
HTTP/2: modified ngx_http_v2_send_chain() loop to be safer.
Previously, the loop used a "limit == 0" condition, and only at the end
of the loop. In case of other issues, such as "limit" being negative
due to h2c->send_window being large enough to overflow off_t, this
resulted in incorrect buffer construction and subsequent segmentation
faults or memory corruption.
With the change, "limit > 0" is checked as the loop condition, and this
ensures that the loop is safely terminated if "limit" ever becomes
negative due to a bug,
diff --git a/src/http/v2/ngx_http_v2_filter_module.c b/src/http/v2/ngx_http_v2_filter_module.c
--- a/src/http/v2/ngx_http_v2_filter_module.c
+++ b/src/http/v2/ngx_http_v2_filter_module.c
@@ -975,7 +975,7 @@ ngx_http_v2_send_chain(ngx_connection_t
cl = NULL;
#endif
- for ( ;; ) {
+ while (limit > 0) {
if ((off_t) frame_size > limit) {
frame_size = (size_t) limit;
}
@@ -1070,10 +1070,6 @@ ngx_http_v2_send_chain(ngx_connection_t
}
limit -= frame_size;
-
- if (limit == 0) {
- break;
- }
}
if (offset) {
More information about the nginx-devel
mailing list