From nobody Sat Oct 29 21:10:51 2022 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 4N0BsS0Fcnz4gsQQ; Sat, 29 Oct 2022 21:10:52 +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 4N0BsR6xSZz3ZdZ; Sat, 29 Oct 2022 21:10:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667077852; 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=27eFfqKEjfQcaDA1G4r45SIWQNcLqvD0jeJ9/G3ho1I=; b=daisJOXXMAH+jGOopaMAof11LAZ8YmW7XZcpLRlvmxnPST6TcFZQZt9xKO5lbMeEilwOx7 4+naw3wh8tywzKn9CZonANUJTLAr+bpNKRdYCQGE/vrzoxPpZMdVGBL013kY7ee10xFsMK pRxZIVrd7no9uJSi1nRTErqjqsnQjbTKqv6FaHiswYcaZOqDsrzs3qvY0jxV3iqkAW6G5C 8GChQo9coI5caiN/Kqx/EWF7X9/ih5xWn9I3OKvBnLk/0z6eUGt6Wd81C4Gp5vQ4qpaP56 dOvZJZMNJkECeYrxRTk1pXfwKCzTEpnEkFjgEiCNbfeK26eW9HuO7XdIWCjAPQ== 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 4N0BsR60h7zXWJ; Sat, 29 Oct 2022 21:10:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29TLApA1067964; Sat, 29 Oct 2022 21:10:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29TLApYx067963; Sat, 29 Oct 2022 21:10:51 GMT (envelope-from git) Date: Sat, 29 Oct 2022 21:10:51 GMT Message-Id: <202210292110.29TLApYx067963@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: edcee003e5a7 - main - strfmon_test: Reserve space for the null terminator 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: edcee003e5a79386653c8092af3577a112e95451 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667077852; 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=27eFfqKEjfQcaDA1G4r45SIWQNcLqvD0jeJ9/G3ho1I=; b=GGCzli4dNPB69/eutR1NfYqieNMCCq1NILkWbw/fJkwkHuhZ8B/f42tFE6RTPPjLUCnXuM XpENtceOa7oj1PgiAmX5plsSO3jNdb9y+cfjSPtbgQH1pz4Tq5ZWXBlFELufQzSNXg0d8Q H//gYCa1x/ETo5VhsrwO9fW4CAcN62D7zyVwp5brQRN+wRZYxiNemsJCiBST9qWzFGMjbS t27hsmwoHj5cx4r115uZNKd8OsKfBkSMEjWtV59jjPqU1GtJ/xmv6S3W1iO9YRGgLJOWy4 XRPIBju9VsCHY6k/ZM0DNsxl05QOclM/wUnlEixm2BpbwuMBwYYXE0/UaF0Ubw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667077852; a=rsa-sha256; cv=none; b=PcuWUWWBbSNtmTFpsaQUKDcmsUwZwRBXK6dF7b37y3JMMYLykQ7FUV0J8gYEQQp8cVrC1h kwhcGPavcChCu9PAcYO9z9hE8/xNRMqdRdjcRY0DFv/BqagtGB0gXEcZ+yF0nF7paPb/qE hXMe+O0U5UL8DVwSZVFm+Aa0tj650GzMbG1FnztfcAYDBS8+8t9r++qvvPrIDSuPP2ZYGq WZfAid8roSsWiuS0ucelkOzd2h2HqeMvp5QGy87McazNHik7eblwatFBPPoOeKDExSbZSy oSv/Cei9C5F39Fae2r+Iwj+npjZFQANWK2+Yd0i8yg7VlzYQ0hNDJfjDHk6OPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=edcee003e5a79386653c8092af3577a112e95451 commit edcee003e5a79386653c8092af3577a112e95451 Author: Jose Luis Duran AuthorDate: 2022-10-27 10:01:24 +0000 Commit: Konstantin Belousov CommitDate: 2022-10-29 21:08:33 +0000 strfmon_test: Reserve space for the null terminator Otherwise strfmon(3) could overflow the buffer. Here is mostly done for correctness and illustrative purposes, as there is no chance it could actually happen. Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week --- lib/libc/tests/stdlib/strfmon_test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index d8e4f478547a..c2fa6250dc58 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -55,7 +55,7 @@ ATF_TC_BODY(strfmon_locale_thousands, tc) atf_tc_skip("multi-byte thousands-separator not found"); n = 1234.56; - strfmon(actual, sizeof(actual), "%i", n); + strfmon(actual, sizeof(actual) - 1, "%i", n); strcpy(expected, "1"); strlcat(expected, ts, sizeof(expected)); @@ -95,7 +95,7 @@ ATF_TC_BODY(strfmon_examples, tc) for (i = 0; i < nitems(tests); ++i) { snprintf(format, sizeof(format), "[%s] [%s] [%s]", tests[i].format, tests[i].format, tests[i].format); - strfmon(actual, sizeof(actual), format, + strfmon(actual, sizeof(actual) - 1, format, 123.45, -123.45, 3456.781); ATF_CHECK_STREQ_MSG(tests[i].expected, actual, "[%s]", tests[i].format); @@ -135,7 +135,7 @@ ATF_TC_BODY(strfmon_cs_precedes_0, tc) for (j = 0; j < 5; ++j) { lc->n_sign_posn = j; - strfmon(buf, sizeof(buf), "[%n] ", -123.0); + strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0); strlcat(actual, buf, sizeof(actual)); } @@ -178,7 +178,7 @@ ATF_TC_BODY(strfmon_cs_precedes_1, tc) for (j = 0; j < 5; ++j) { lc->n_sign_posn = j; - strfmon(buf, sizeof(buf), "[%n] ", -123.0); + strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0); strlcat(actual, buf, sizeof(actual)); } @@ -206,7 +206,7 @@ ATF_TC_BODY(strfmon_international_currency_code, tc) if (setlocale(LC_MONETARY, tests[i].locale) == NULL) atf_tc_skip("unable to setlocale()"); - strfmon(actual, sizeof(actual), "[%i]", 123.45); + strfmon(actual, sizeof(actual) - 1, "[%i]", 123.45); ATF_CHECK_STREQ(tests[i].expected, actual); } }