From patchwork Fri Jul 21 12:18:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 73044 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DC0F3853D15 for ; Fri, 21 Jul 2023 12:18:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DC0F3853D15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689941931; bh=QW/xEoCRLF5k9y2T1ZplaxLDStqg9GtToBXvdd4xOo4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PxaN7zCBv0cSKeVGjCXvJ/xsIlV8VKV2n7xv27EOdXR4BBcKFY9RssPr71oW6xMhA +4uO5RhRuWNay4K3ffRRpKavKyB4zaoKj7+dD8UaQI1MZFYjOxsBdsyJRAiK0nmjq3 B8lAoEsg2ifq12/zANEQnp1IA4N1biRSLE72MvEc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id C7E303858409 for ; Fri, 21 Jul 2023 12:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7E303858409 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6bb14015560so324976a34.2 for ; Fri, 21 Jul 2023 05:18:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689941905; x=1690546705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QW/xEoCRLF5k9y2T1ZplaxLDStqg9GtToBXvdd4xOo4=; b=IqyPJ5O1p5bT0CZ65DrxrYsNFIZUsor448fb2IwdSa+LG0cyE71HcOhV+R55EbKYnX TWygHbB2iXTqf5G7qMwXXu1Vy0t0YN07EdufYl+rT9cUOxtgA8EY1tVjj9NCklhcUxXz u87RpOIww3bbH6O0cvNordcwDoeXckR+Lepj/7Pt97hTCk0SuAhHzn5Cy70OIcSscnm+ XjKOtfUdZpQMgCHr3xOhIl4CrOmXrpQ9N9FvSJDBffZ38GPlQ7PNcjJvFl9UhuNNDdly p2CjZS9+tArjN6QX86FgcFVHjfE4PbTiPEMINY0nDAzhBbzEnjNmf6poL0ivqV/bw4jd oMqw== X-Gm-Message-State: ABy/qLadgPioMxii+N8r74WlQxMX2i2SwOy+XbprMJpqlnQDrq5zseW5 DVGgsq8lcSVx278umRxcvTaITKjs2FVfhWzco7l9gA== X-Google-Smtp-Source: APBJJlFW5HaWXY6EUi5VrgC+zdInHzWuXBYdtbgmG/ctvxufV/VxID/P2279ZPKPbJMOAAhCn5/QUg== X-Received: by 2002:a05:6830:85:b0:6b9:a979:5b5f with SMTP id a5-20020a056830008500b006b9a9795b5fmr1790632oto.2.1689941905471; Fri, 21 Jul 2023 05:18:25 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d4d2:3e68:c30b:c219:d30a]) by smtp.gmail.com with ESMTPSA id i14-20020a9d650e000000b006b8a2cd44adsm1296196otl.72.2023.07.21.05.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 05:18:24 -0700 (PDT) To: libc-alpha@sourceware.org, Frederic Berat Subject: [PATCH 1/3] posix: Fix test-errno build with fortify enable Date: Fri, 21 Jul 2023 09:18:15 -0300 Message-Id: <20230721121817.1978446-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> References: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" With gcc 11.3.1, building with -D_FORTIFY_SOURCE=2 shows: In function ‘getgroups’, inlined from ‘do_test’ at test-errno.c:129:12: ../misc/sys/cdefs.h:195:6: error: argument 1 value -1 is negative [-Werror=stringop-overflow=] 195 | ? __ ## f ## _alias (__VA_ARGS__) \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../posix/bits/unistd.h:115:10: note: in expansion of macro ‘__glibc_fortify’ 115 | return __glibc_fortify (getgroups, __size, sizeof (__gid_t), | ^~~~~~~~~~~~~~~ ../posix/bits/unistd.h: In function ‘do_test’: ../posix/bits/unistd-decl.h:135:28: note: in a call to function ‘__getgroups_alias’ declared with attribute ‘access (write_only, 2, 1)’ 135 | extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]), | ^~~~~~~~~~~~~~~~~ ../misc/sys/cdefs.h:264:6: note: in definition of macro ‘__REDIRECT_NTH’ 264 | name proto __asm__ (__ASMNAME (#alias)) __THROW It builds fine with gcc 12 and gcc 13. Checked on x86_64-linux-gnu. --- posix/test-errno.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/posix/test-errno.c b/posix/test-errno.c index 305bc42938..3ef711bb41 100644 --- a/posix/test-errno.c +++ b/posix/test-errno.c @@ -17,6 +17,10 @@ License along with the GNU C Library; if not, see . */ +#include +/* Triggered by getgroup fortify wrapper. */ +DIAG_IGNORE_NEEDS_COMMENT (6, "-Wstringop-overflow"); + #include #include #include @@ -34,7 +38,6 @@ #include #include #include -#include /* This is not an exhaustive test: only system calls that can be persuaded to fail with a consistent error code and no side effects From patchwork Fri Jul 21 12:18:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 73045 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D370E3851409 for ; Fri, 21 Jul 2023 12:19:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D370E3851409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689941972; bh=68RX4NEJT+cpT+tloXjIdOq20rTPulVS0YAWvSczqZI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Yn8h8wer2DRtyeMEKOYj38At0/tnaD4jfQngWpwzaJdiTRwb66cxfcXsEpSJ7tCNP Pjy/QZmUAfd7ai8td9AOCJQQ8PC44yGX9ZWZpKxnmexLq532cGJ8xsVsnfCI3XINlS BXfFL/YEPgpIvR3tdPb5hLgd6q1CcnMS1tD5P9Mg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id A146D385C017 for ; Fri, 21 Jul 2023 12:18:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A146D385C017 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6b9f46dc2e3so1380962a34.0 for ; Fri, 21 Jul 2023 05:18:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689941907; x=1690546707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=68RX4NEJT+cpT+tloXjIdOq20rTPulVS0YAWvSczqZI=; b=IVkBNjabffUfoWfaOJwbuh9iAyQqji+rTc2XuNU1DW4LUoHkUZdwZXFynYsG5mq149 7MdoG9hBUT7pKAia5NQd9vOo7EG8KNn3yK21YeTe04Pw8Q5nWJzr76p3aWfYgFnAv2Un +xHcqJ10RqFTkSEDRS+kLSVbw/GziS6bavf/+tY3vdbVeYX+3acAuPSYsBqvkNVSy6p+ kDhua00lZWzI0PCDQPB5ugIvlpk4LaCBI7+irxSfipzZIi1qMc0Ey+atAYtb4lEk/a+e vipURD4oPryaX2f1X82juT06HTobDmHPsz8GDBhY2P9+5khVUcmPSGguogc/aBFAFO2B orGw== X-Gm-Message-State: ABy/qLbshEeTDIriiu29eoSDo1l8G6zTG+4n9y97CmbL3BWxaji4APnX N8ABh2el/vyivA3e3UxuYDR5Xr+qfw9NeHve9wHr6Q== X-Google-Smtp-Source: APBJJlGA4xJTDqhmVatWLKM5deqrLnyF+gfOzh7HkSH0dWRP7Y9Sg8Q4FnGa4mXLBcyDJ+syhzt9Nw== X-Received: by 2002:a05:6830:22f0:b0:6b9:c41f:ede9 with SMTP id t16-20020a05683022f000b006b9c41fede9mr1758034otc.16.1689941907326; Fri, 21 Jul 2023 05:18:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d4d2:3e68:c30b:c219:d30a]) by smtp.gmail.com with ESMTPSA id i14-20020a9d650e000000b006b8a2cd44adsm1296196otl.72.2023.07.21.05.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 05:18:26 -0700 (PDT) To: libc-alpha@sourceware.org, Frederic Berat Subject: [PATCH 2/3] string: Fix bug-strncat1 with fortify enabled Date: Fri, 21 Jul 2023 09:18:16 -0300 Message-Id: <20230721121817.1978446-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> References: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" If fortify is enabled, the truncated output warning is issued by the wrapper itself: bug-strncat1.c: In function ‘main’: bug-strncat1.c:14:3: error: ‘__builtin___strncat_chk’ output truncated copying 1 byte from a string of length 2 [-Werror=stringop-truncation] 14 | strncat (d, "\5\6", 1); | ^ Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell --- string/bug-strncat1.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/string/bug-strncat1.c b/string/bug-strncat1.c index 65a7ed58c2..cdd2141191 100644 --- a/string/bug-strncat1.c +++ b/string/bug-strncat1.c @@ -1,9 +1,16 @@ #undef __USE_STRING_INLINES #define __USE_STRING_INLINES +#include +#include +#if __GNUC_PREREQ (8, 0) +/* GCC warns about strncat truncating output; this is deliberately + tested here. If fortify is enabled, it is also triggered by the + wrappers. */ +DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif #include #include #include -#include char d[3] = "\0\1\2"; @@ -11,11 +18,6 @@ int main (void) { DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about strncat truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif strncat (d, "\5\6", 1); DIAG_POP_NEEDS_COMMENT; if (d[0] != '\5') From patchwork Fri Jul 21 12:18:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 73046 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 203AD3853546 for ; Fri, 21 Jul 2023 12:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 203AD3853546 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689941974; bh=XwD9NRW+kJwHnx1hrZASruTKeP6UP8NBu0ehFn58GqE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eulEAgbEemw433ryAuLWWpI2R7/6bBXI6RXoF7IRHW3knlFpmm4PNZ9KqAMnsp1Ri InKMLlHcvgyCIPFdiXhgaJDjl0ujj/4xcVW87dnplJPzMtW5wJ90Xe1XtmryxlGlog 0ZRn2BJrOJbClGy3dfKI0+o4hEBuXJpshBePMKQA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 48CB6385483D for ; Fri, 21 Jul 2023 12:18:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48CB6385483D Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6b9ede6195cso1594827a34.3 for ; Fri, 21 Jul 2023 05:18:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689941909; x=1690546709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XwD9NRW+kJwHnx1hrZASruTKeP6UP8NBu0ehFn58GqE=; b=bex6XaGwl7j+bw5ZrcI2FEk908SO5JOv34WZvgQOi1ubMDj6YqgETEcFWDYfzXeP2D wnGxHj17S/Y3q5sfVWX+LnKBzGxrHThAFBmM64ZuDDZh9o7GPw3pYDQyQbnIBhXLf1ks xYWb55v1SoadT33Vr1x9kA9kOBPjgXRPw7xk3sdi3UvoL4cmODOtDKMSqYmVJVL/LQqR JMyiLzP31PEldAd1+yXPEgwzy9in4su7y3/9UokcwvUSZ2ow79YCMy8B0DVIcxA9D1P7 o54eBX/MajV+XxZxA6HCLpgxWfSlV1zdq5/Ib/sMi3rygbapxTMrfz+5ebL+9GLIhY1W BXxw== X-Gm-Message-State: ABy/qLaR/QdscK0cTvelJmCBmfS1cE27sfssDudpfRbG5Ukq7nuRoXns CMrHzPz4udBc40u+BNNdogXm/Sh9mpWw5jnN8weavA== X-Google-Smtp-Source: APBJJlEyzEhkOCFlosQYHxf/XpkZcZDf7D8VIjJsNwKbgXCUL/iw+RuXAcHidzMfChLwklISlQ14Tw== X-Received: by 2002:a9d:730b:0:b0:6b9:c186:38c7 with SMTP id e11-20020a9d730b000000b006b9c18638c7mr1606765otk.29.1689941909113; Fri, 21 Jul 2023 05:18:29 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d4d2:3e68:c30b:c219:d30a]) by smtp.gmail.com with ESMTPSA id i14-20020a9d650e000000b006b8a2cd44adsm1296196otl.72.2023.07.21.05.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 05:18:28 -0700 (PDT) To: libc-alpha@sourceware.org, Frederic Berat Subject: [PATCH 3/3] string: Fix tester with fortify enabled Date: Fri, 21 Jul 2023 09:18:17 -0300 Message-Id: <20230721121817.1978446-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> References: <20230721121817.1978446-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" If fortify is enabled, the truncated output warning is issued by the wrapper itself: In function ‘strncpy’, inlined from ‘test_strncpy’ at tester.c:505:10: ../string/bits/string_fortified.h:95:10: error: ‘__builtin_strncpy’ destination unchanged after copying no bytes from a string of length 3 [-Werror=stringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../include/bits/string_fortified.h:1, from ../string/string.h:548, from ../include/string.h:60, from tester.c:33, from inl-tester.c:6: In function ‘strncpy’, inlined from ‘test_strncpy’ at tester.c:505:10: Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell --- string/tester.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/string/tester.c b/string/tester.c index 8de70ad3ce..da42c72141 100644 --- a/string/tester.c +++ b/string/tester.c @@ -26,6 +26,14 @@ #undef __USE_STRING_INLINES #endif +#include +#include + +/* Triggered by strncpy fortify wrapper when it is enabled. */ +#if __GNUC_PREREQ (8, 0) +DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif + #include #include #include @@ -33,7 +41,6 @@ #include #include #include -#include /* This file tests a range of corner cases of string functions, including cases where truncation occurs or where sizes specified @@ -45,9 +52,6 @@ DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args"); DIAG_IGNORE_NEEDS_COMMENT (9, "-Wrestrict"); DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); #endif -#if __GNUC_PREREQ (8, 0) -DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif #if __GNUC_PREREQ (11, 0) DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread"); #endif