From nobody Wed Sep 06 21:56:31 2023 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 4Rgx6767M3z4sJFr; Wed, 6 Sep 2023 21:56:31 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rgx675Zp5z3ZZn; Wed, 6 Sep 2023 21:56:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694037391; 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=C4CUMX35OgZQ93p62pdTf+7Uxxjh18FG0laaSUu1Jwc=; b=DifiebWLk5KWgIMSxMQKnwQiRk3T07DkE7Wn4eodGVm/sxZoRr8foBjqniYm5/blF34mmm aqnYN2cXLtmYtyJ7KzM4p8N3Hjmxth6/H4pjsRgd7sbSk2Ox+6ryhS4tYktJQ59OVeArpi d+fyDWrrjIOtH+zV9QpBSJAls1odj4ZT9zNOlHDZ2TpcZNKYZ4qNoI1J04OlBmN8lXxZVR HsGgVd5p8o1QUf63sZpojc1yRyXQwZl3r2NI+TQ6KgsYz5WucDVO4yiwCXXErkG3cernhu /DLgml6CaQiKYgpp0+VbEJdw5AMpD001n1lUtuF4wCNHQH2WVUQ7Db5PO8VKRw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694037391; a=rsa-sha256; cv=none; b=G+kgBW/7YpCNYYPJsliQTT12uhI680MxCqN7/iatODk2na9P/uxZBVzPuw3c1t6+X5FUkD BWU8GPXItP+B4xriot9YBDnya7WB/K2X7UscUyXer8ElE83c7hLVwPwQRqqyRRHSGJOG/p mxA/9o1hv3AN1w3etAZgQVw+J4g3+rYuSA53Cq3mRTUfb2lHZfxgigFAfWkLsQ8yuek1nJ FFZvAlQ342wRPXkSDhmZi2xzfrORL7TeD90Iv5aFHA4Tk68JxeZT/h2E86fi1pCRg31KUp TZIpLgnU0xGTfDQpNqbWTdx9dwvIbiu6vAR8ZoR2AKWqN0PIb86BRG9KYxwkzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694037391; 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=C4CUMX35OgZQ93p62pdTf+7Uxxjh18FG0laaSUu1Jwc=; b=c4TwTq4tcm41fa+qDHDaxapeDAnv2LA0wBbVukr0ciTezPYaQvJI6w9YBP6HOB+yaf3mOD Gy4bfpLOS8bV2FLTZZ7o9xoQaNfQCfNqLJadbLiBkPZ3/2LQOGJXyphWzBwWD//ivaz574 PHJFNtxAwOgheNqTqYtBZWAlkZ59k/LIfQCuHghAo0o16QMOdqZ8/YUJcr+m6MFoWHwgEq GwOmQMee2d0igmopZ2yxrXc8u2C4bJY/DVT52c2dm7lt2cjuN9pA8Z7bi/FeoyrnmCDRN6 H3pGdFRIxljshI4neFP/eYvILVN24FGmqQRsBUBM1EU55E0+ga0iPM6M2yj6Sw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Rgx674d7CzYkB; Wed, 6 Sep 2023 21:56:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 386LuVPs022375; Wed, 6 Sep 2023 21:56:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 386LuVft022372; Wed, 6 Sep 2023 21:56:31 GMT (envelope-from git) Date: Wed, 6 Sep 2023 21:56:31 GMT Message-Id: <202309062156.386LuVft022372@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 519395f62d29 - stable/13 - h_resolv: Fix a buffer overflow in load(). 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 519395f62d2966faf83990d4162cc5b39af06c75 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=519395f62d2966faf83990d4162cc5b39af06c75 commit 519395f62d2966faf83990d4162cc5b39af06c75 Author: John Baldwin AuthorDate: 2022-12-28 17:39:18 +0000 Commit: John Baldwin CommitDate: 2023-09-06 21:56:09 +0000 h_resolv: Fix a buffer overflow in load(). fgetln() returns a pointer to an array of characters that is 'len' characters long, not 'len + 1'. While here, overwriting the contents of the buffer returned by fgetln isn't really safe, so switch to using getline() instead. Note that these fixes are a subset of those applied to a near-identical copy of this function in libc's resolv_test.c in commit 2afeaad315ac19450389b8f2befdbe7c91c37818. Reviewed by: ngie Reported by: CHERI (buffer overflow) Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D37886 (cherry picked from commit d131218534977f1b2ed590380e70d59a3b20b333) --- contrib/netbsd-tests/lib/libpthread/h_resolv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/netbsd-tests/lib/libpthread/h_resolv.c b/contrib/netbsd-tests/lib/libpthread/h_resolv.c index 9c5fedcc2e7f..d8756de96d23 100644 --- a/contrib/netbsd-tests/lib/libpthread/h_resolv.c +++ b/contrib/netbsd-tests/lib/libpthread/h_resolv.c @@ -73,18 +73,18 @@ static void load(const char *fname) { FILE *fp; - size_t len; + size_t linecap; char *line; if ((fp = fopen(fname, "r")) == NULL) err(1, "Cannot open `%s'", fname); - while ((line = fgetln(fp, &len)) != NULL) { - char c = line[len]; + line = NULL; + linecap = 0; + while (getline(&line, &linecap, fp) >= 0) { char *ptr; - line[len] = '\0'; + for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS)) sl_add(hosts, strdup(ptr)); - line[len] = c; } (void)fclose(fp);