From nobody Wed Jun 10 04:01:11 2026 X-Original-To: dev-commits-src-branches@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 4gZsX83Rp3z6gvHs for ; Wed, 10 Jun 2026 04:01:12 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gZsX80rJ2z3wFB for ; Wed, 10 Jun 2026 04:01:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781064072; 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=BSFguV6Tm064NtEG3uEiaL7fesz/Z86Za38lrvgDdN0=; b=UktGk3Yzo7S/3+1+6XkSlRAqDAEuHohKK3QeQiV5lDFkKU+foDPG7+rSky21a+DUoSJVgu xPv2kNf8GYgr/iMkb4i1sfG1K45Qwp6WNjE9PvUdepG70k5Lql/cEEGfTdU9n7irbxvWMM YxxQOfc0HaSN0LgknPmWewfk0rmIbVIhMMjZZ/GrYFaNPTcK/TEE+biDIeSw09RXPEaer8 TwiyfkP+TpA5IvPJFK657k6bCbwFm6MgURJkSahgrCv0jEIU583QcqA4ztUGKSkR4ZOMj0 aoRrTIxWJD4ak5Z7Dmu6Fm0Ba83gZxdLBWfRFphx+gg3g0ntRM4bM5h+eunfog== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781064072; a=rsa-sha256; cv=none; b=UekQxlQgOlTVcfeKw3QAx/y8xjmkFXGiWX4ntcz7cgFTishb2oo2H3oEqAypzJ1KtqRdHC Vf2FPzwTQET+UCDWh1DnDZeTKJ7cu13PLmQ3Pi6gzVTyXOlehJJYqysRNSYybOpU7aRUES MCTKTE1a6MGPljWnSIFo2XYnEgPWoWohfXTni0+oKkMPQZzM2bNIiKuM14K01xvsDrqNcI eRb/yg7HghqdFxLEMzOPLUQz9v9LRY/mpGhsBSM0JqKAuvqxwlS6L2s9hkoPKdThug5DHi qNFdOeYHOMGbHoS1VxR8Bt0qvXzkc3v5q/Db7VqJEl7806VhDUxzBEBrJjhN6g== 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=1781064072; 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=BSFguV6Tm064NtEG3uEiaL7fesz/Z86Za38lrvgDdN0=; b=comdgh1LrL19bwCfDCuivUoJ6KQyZylhrRL4xbiB16vNzGb0kZzNR8I7rRhPLbtqK4zNbO y4PaA0C5GlMK3DP7xmdxC1Yp6tszUIWQDHOsZCOuZ9WcURkfI3TaftVUj9PLj2PBexKeV4 i2A95rFjSL/svwIwGJm+Yyq7a28OIeYrnw6/cOI0EkrHS8Vm3mHgI4gecwm9usVZlZks/+ 0WSkqnfysuyKZq0KndbMRe8LjpgneygR78eTZnZksIwr9aCA/09DRK7dA0ZadObBwqA9Jj yP2xP+vCnOWG4Q2SJ3VwBERqCVWaRBbNkTh1bqWcNAWCY/nuFm30s0cc0XlgXw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gZsX76r4tz143L for ; Wed, 10 Jun 2026 04:01:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25e6b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 10 Jun 2026 04:01:11 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 52e2e6bfc31a - stable/15 - ssp: fix our gets_s implementation under _FORTIFY_SOURCE List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 52e2e6bfc31a54e53109978434bc8c43005aa367 Auto-Submitted: auto-generated Date: Wed, 10 Jun 2026 04:01:11 +0000 Message-Id: <6a28e187.25e6b.65fd6282@gitrepo.freebsd.org> The branch stable/15 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=52e2e6bfc31a54e53109978434bc8c43005aa367 commit 52e2e6bfc31a54e53109978434bc8c43005aa367 Author: Kyle Evans AuthorDate: 2026-05-01 02:57:51 +0000 Commit: Kyle Evans CommitDate: 2026-06-10 04:00:35 +0000 ssp: fix our gets_s implementation under _FORTIFY_SOURCE Annex K specifies an interface for handling constraint violations from gets_s, but we previously broke this for some classes of get_s misuse. Provide a more nuanced version that tries to dodge errors that would trigger a constraint handler while still providing value. Notably, we don't want to trigger a failure unless the passed-in length reasonably fits within an RSIZE_MAX, because gets_s will immediately call larger lengths bogus and fail. PR: 294881 Reviewed by: markj (cherry picked from commit d98f4f0698ef0c5178882c544b4c38542d4780f0) --- include/ssp/stdio.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h index 630683951e4b..17bda8d3ee2d 100644 --- a/include/ssp/stdio.h +++ b/include/ssp/stdio.h @@ -36,6 +36,10 @@ #include +#if __SSP_FORTIFY_LEVEL > 0 && __EXT1_VISIBLE +#include +#endif + __BEGIN_DECLS #if __SSP_FORTIFY_LEVEL > 0 #if __POSIX_VISIBLE @@ -51,7 +55,31 @@ __ssp_redirect(size_t, fread, (void *__restrict __buf, size_t __len, __ssp_redirect(size_t, fread_unlocked, (void *__restrict __buf, size_t __len, size_t __nmemb, FILE *__restrict __fp), (__buf, __len, __nmemb, __fp)); #if __EXT1_VISIBLE -__ssp_redirect(char *, gets_s, (char *__buf, rsize_t __len), (__buf, __len)); +__ssp_redirect_raw_impl(char *, gets_s, gets_s, + (char *buf, rsize_t len)) +{ + char *retbuf; + size_t bufsz; + int need_fail = 0; + + /* + * If we would have overwritten our buffer, we want to fail the check + * only if these arguments wouldn't have triggered a constraint + * violation. + */ + bufsz = __ssp_bos(buf); + if (bufsz != (size_t)-1 && (size_t)len > bufsz) { + if (len <= RSIZE_MAX) + __chk_fail(); + need_fail = 1; + } + + retbuf = __ssp_real(gets_s)(buf, len); + if (need_fail && retbuf != NULL) + __chk_fail(); + return (retbuf); +} + #endif /* __EXT1_VISIBLE */ __ssp_redirect_raw(char *, tmpnam, tmpnam, (char *__buf), (__buf), 1, __ssp_bos, L_tmpnam);