From nobody Wed Sep 30 16:55:46 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hw1QB6r5Yz6tq7k for ; Wed, 30 Sep 2026 16:55:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hw1QB6Lk9z4jws for ; Wed, 30 Sep 2026 16:55:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790787346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ojz/XT+15Bh+hLe1jb68NjIKmXx8wJlo2swdStw8Wx4=; b=n/MJHy1J0DBH+WdqDtma3Bc0SfMMkNeuYoV2Gth5UQr6tU47jBN8q7CGSEZcDXbulDxMVo AdJ5IksrvIaouLLv2vXgLh3PWLx6ePdbiOzYHE+weXGieqwBByRJac5WUS5CV1IZeHYhh1 Fh29WX6wSgxiEg/HqLw0iE5fEwMmwVLkM4yG8qH9hXjgL9WaEkhtobdaQ6sqD5ImXXn/5f 4b8QyUGget+kXd4cK1mf2k6aXOve5NJnaQWyI2GuvA8BkT7/s2CdI0Nz4uabSkf+lw+0Ec QKz0ji7QlmjxBKDsTZBUBuzBPCLBEwUj7jHMLpqnqE0MYFANZs6VNFAWpFwNHA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790787346; b=KiQVZEwJzWTuskixTqkv0BXX4bnS+TY+E5m1bIvw6NRPuEzqZoD1AjltwFvnqgkfVp8knN QTTYV0jJEZ3814mEDAXH38deJ3AHAIHWHX5aub40N7U6Vr8t8p5g+0u3xOGgyJ4gRZvLIA xDhY+qacS1cgAKQ/9pNtrDq6FP0ZFKdOT5lo3ll3nnDx1Y1yFz6kfFRNceatHMuydCkN3n S8gtamet/PW4EHLXlqJYXzhwFw1NVr89eeMquZcRgjYJTX0jEAtQAfg/FhWyR2aIGH6tHf qR+qkvY7qgnrheGHWafQFoYEWWlupkw1x113GSeZM5e4KrQzNrSphosSOctzbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790787346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ojz/XT+15Bh+hLe1jb68NjIKmXx8wJlo2swdStw8Wx4=; b=VRLamNEIUfn+/A6s6++wywasKJ6DUS0RZAsAKGzy2NOVu83BHEkSgApOu4TJNx1oVCPTnK Rq0rRNrhZ1u63i5ARU2r55cMxzzVa8kPvYHjh+qwwiBs4FdR15u1+0Wobg0NqQGvgmf4H7 54hSz9dPXCqTvI4fBoSC65W++LIeu4TWxiAAthd92uoZaQQtXUeS8U4bVC3XbOEQLbGua8 67yzLG5ZOOZdPZqHrvzkXbqgJRIyZrxzdUmTPnTAHvsAD3U/HvKiUE02Xd/nVIaoVBW8Ri hVVIY7pyoH1SPAQJbIYDOJA3pu1sUGWiGR7aUl4/TqOGbwWQsUiV17g5vUhvnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hw1QB59tvztNh for ; Wed, 30 Sep 2026 16:55:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 38ea1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 30 Sep 2026 16:55:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 64ce9daab9ee - main - libfetch: Limit response line length List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 64ce9daab9ee49b4647f43141a830d7518723142 Auto-Submitted: auto-generated Date: Wed, 30 Sep 2026 16:55:46 +0000 Message-Id: <6abd3f12.38ea1.48cf28ae@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=64ce9daab9ee49b4647f43141a830d7518723142 commit 64ce9daab9ee49b4647f43141a830d7518723142 Author: Dag-Erling Smørgrav AuthorDate: 2026-09-30 16:54:25 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-09-30 16:54:25 +0000 libfetch: Limit response line length When reading an FTP or HTTP response, error out if we read 64 kB before hitting a newline. Otherwise a runaway or malicious server could have us spinning for quite a while allocating more and more memory before we gave up or crashed. MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D60007 --- lib/libfetch/common.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index 431fd781ac6a..da0ea6f8aaeb 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -57,6 +57,8 @@ #include "fetch.h" #include "common.h" +/* Maximum length of a line, newline included, for fetch_getln() */ +#define FETCH_LINE_MAX 65536 /*** Local data **************************************************************/ @@ -1466,9 +1468,15 @@ fetch_getln(conn_t *conn) /* look at the data we already have */ if (conn->pos < conn->buflen) { conn->line = conn->buf + conn->pos; - while (conn->pos < conn->buflen) + while (conn->pos < conn->buflen) { if (conn->buf[conn->pos++] == '\n') goto found; + if (conn->buf + conn->pos - conn->line >= + FETCH_LINE_MAX) { + errno = EPROTO; + goto fail; + } + } /* reset for the upcoming memmove() */ conn->pos = conn->line - conn->buf; } @@ -1498,9 +1506,14 @@ fetch_getln(conn_t *conn) if (rlen == 0) break; /* look for a newline */ - while (conn->pos < conn->buflen) + while (conn->pos < conn->buflen) { if (conn->buf[conn->pos++] == '\n') goto found; + if (conn->pos >= FETCH_LINE_MAX) { + errno = EPROTO; + goto fail; + } + } /* do we need a bigger buffer? */ if (conn->buflen > conn->bufsize / 2) { tmp = conn->buf;