Skip to content

Commit 8d08aaa

Browse files
committed
Fix --limit-request-line 0 to mean unlimited
Per documentation, limit_request_line=0 means unlimited. The code was incorrectly treating 0 as "use default max" by checking <= 0 instead of < 0. For the fast C parser (gunicorn_h1c), which doesn't support 0 as unlimited, pass a large value (1MB) instead. This applies to both WSGI workers (http/message.py) and ASGI workers (asgi/protocol.py). Fixes #3563
1 parent d40a374 commit 8d08aaa

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

gunicorn/asgi/protocol.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,18 @@ def _setup_callback_parser(self):
419419
else:
420420
parser_class = PythonProtocol
421421

422+
# Handle limit_request_line=0 (unlimited per documentation)
423+
# PythonProtocol handles 0 correctly, but C parser needs a large value
424+
limit_request_line = self.cfg.limit_request_line
425+
if limit_request_line == 0 and parser_class != PythonProtocol:
426+
limit_request_line = 1024 * 1024 # 1MB for C parser
427+
422428
# Create parser with callbacks and limit parameters (both parsers support them)
423429
self._callback_parser = parser_class(
424430
on_headers_complete=self._on_headers_complete,
425431
on_body=self._on_body,
426432
on_message_complete=self._on_message_complete,
427-
limit_request_line=self.cfg.limit_request_line,
433+
limit_request_line=limit_request_line,
428434
limit_request_fields=self.cfg.limit_request_fields,
429435
limit_request_field_size=self.cfg.limit_request_field_size,
430436
permit_unconventional_http_method=self.cfg.permit_unconventional_http_method,

gunicorn/http/message.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,19 @@ def __init__(self, cfg, unreader, peer_addr, req_number=1):
387387
self.query = None
388388
self.fragment = None
389389

390-
# get max request line size
390+
# get max request line size (0 means unlimited per documentation)
391391
self.limit_request_line = cfg.limit_request_line
392-
if (self.limit_request_line <= 0
393-
or self.limit_request_line >= MAX_REQUEST_LINE):
392+
if self.limit_request_line < 0:
394393
self.limit_request_line = MAX_REQUEST_LINE
394+
# For fast parser: use large value when unlimited (0), since C parser
395+
# doesn't support 0 as unlimited. 1MB should be more than enough.
396+
if self.limit_request_line == 0:
397+
self._fast_limit_request_line = 1024 * 1024 # 1MB
398+
elif self.limit_request_line >= MAX_REQUEST_LINE:
399+
self._fast_limit_request_line = MAX_REQUEST_LINE
400+
self.limit_request_line = MAX_REQUEST_LINE
401+
else:
402+
self._fast_limit_request_line = self.limit_request_line
395403

396404
self.req_number = req_number
397405
self.proxy_protocol_info = None
@@ -433,10 +441,11 @@ def _parse_fast(self, unreader, buf):
433441
while True:
434442
try:
435443
# Pass all limit parameters to C parser
444+
# Use _fast_limit_request_line which handles 0=unlimited
436445
result = _fast_parser_module.parse_request(
437446
data,
438447
last_len=last_len,
439-
limit_request_line=self.limit_request_line,
448+
limit_request_line=self._fast_limit_request_line,
440449
limit_request_fields=self.limit_request_fields,
441450
limit_request_field_size=self.limit_request_field_size,
442451
permit_unconventional_http_method=self.cfg.permit_unconventional_http_method,
@@ -447,7 +456,7 @@ def _parse_fast(self, unreader, buf):
447456
last_len = len(data)
448457
self.read_into(unreader, buf)
449458
data = bytes(buf)
450-
if len(data) > self.max_buffer_headers + self.limit_request_line:
459+
if len(data) > self.max_buffer_headers + self._fast_limit_request_line:
451460
raise LimitRequestHeaders("max buffer headers")
452461
except _fast_parser_module.LimitRequestLine as e:
453462
raise LimitRequestLine(str(e))

tests/requests/invalid/limit_line_default_01.http

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/requests/invalid/limit_line_default_01.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)