From patchwork Mon May 17 14:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 43437 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 882283858024; Mon, 17 May 2021 14:20:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 882283858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1621261203; bh=aJNQCWTQoKkMYCfIHxiNXy+FYtC8kDNFmqnxEkqNW3E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mnT+WTlgPOdyFeADYQPyHRDzgN/E2D11s/dWf3z/I7qesgXR9HYflGsnTQPZVLDIm nzjkXt3OIRxTyGlf/2ikC2CcEXevVD1UdygqRDy4VrTSD7nxcV0S+E57H8NspcZXVr es1rFpyfKo5a8BRw9S/7lNvU5INv8Bc5jvn+uE58= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id C50AB3858024 for ; Mon, 17 May 2021 14:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C50AB3858024 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14HE4GZS066752 for ; Mon, 17 May 2021 10:19:51 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38kkmkvc0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 May 2021 10:19:51 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14HE4KE5067240 for ; Mon, 17 May 2021 10:19:51 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 38kkmkvbyv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 May 2021 10:19:50 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14HEGoeP006310; Mon, 17 May 2021 14:19:49 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 38j5x88ugt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 May 2021 14:19:49 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14HEJkaL20120028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 May 2021 14:19:46 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 385304C046; Mon, 17 May 2021 14:19:46 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CF8D4C050; Mon, 17 May 2021 14:19:46 +0000 (GMT) Received: from t35lp56.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 May 2021 14:19:45 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v2] Fix stringop-overflow warning in bug-regex19.c. Date: Mon, 17 May 2021 16:19:36 +0200 Message-Id: <20210517141936.4122773-1-stli@linux.ibm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Kl9W4xarDONu27nt7szvVLy0DI-YHFji X-Proofpoint-ORIG-GUID: 3nr35byvTjaT2tkoBhWUX1uTLJ3jLUXp X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-17_05:2021-05-17, 2021-05-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 spamscore=0 mlxscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105170100 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Stefan Liebler via Libc-alpha From: Stefan Liebler Reply-To: Stefan Liebler Cc: Stefan Liebler , msebor@redhat.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Starting with commit 26492c0a14966c32c43cd6ca1d0dca5e62c6cfef "Annotate additional APIs with GCC attribute access.", gcc emits this warning on s390x: In function ‘do_one_test’, inlined from ‘do_mb_tests’ at bug-regex19.c:385:11: bug-regex19.c:271:9: error: ‘re_search’ specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] 271 | res = re_search (®buf, test->string, strlen (test->string), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 272 | test->start, strlen (test->string) - test->start, NULL); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../include/regex.h:2, from bug-regex19.c:22: bug-regex19.c: In function ‘do_mb_tests’: ../posix/regex.h:554:17: note: in a call to function ‘re_search’ declared with attribute ‘read_only (2, 3)’ 554 | extern regoff_t re_search (struct re_pattern_buffer *__buffer, | ^~~~~~~~~ ... The function do_one_test is inlined into do_mb_tests on s390x (at least with gcc 10). If do_one_test is marked with __attribute__ ((noinline)), there are no warnings on s390x. If do_one_test is marked with __attribute__ ((always_inline)), there are the same warnings on x86_64. test->string points to a variable length array on stack of do_mb_tests and the content is generated based on the passed test struct. According to Martin Sebor, this is a false positive caused by the same bug as the one in nss/makedb.c. It's fixed in GCC 11 and will also be available in the next GCC 10.4 release. --- posix/bug-regex19.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/posix/bug-regex19.c b/posix/bug-regex19.c index 9bbffb17e3..b3fee0a730 100644 --- a/posix/bug-regex19.c +++ b/posix/bug-regex19.c @@ -24,6 +24,7 @@ #include #include #include +#include #define BRE RE_SYNTAX_POSIX_BASIC #define ERE RE_SYNTAX_POSIX_EXTENDED @@ -268,8 +269,17 @@ do_one_test (const struct test_s *test, const char *fail) return 1; } +#if __GNUC_PREREQ (10, 0) && !__GNUC_PREREQ (11, 0) + DIAG_PUSH_NEEDS_COMMENT; + /* Avoid GCC 10 false positive warning: specified size exceeds maximum + object size. */ + DIAG_IGNORE_NEEDS_COMMENT (10, "-Wstringop-overflow"); +#endif res = re_search (®buf, test->string, strlen (test->string), test->start, strlen (test->string) - test->start, NULL); +#if __GNUC_PREREQ (10, 0) && !__GNUC_PREREQ (11, 0) + DIAG_POP_NEEDS_COMMENT; +#endif if (res != test->res) { printf ("%sre_search \"%s\" \"%s\" failed: %d (expected %d)\n", @@ -280,8 +290,17 @@ do_one_test (const struct test_s *test, const char *fail) if (test->res > 0 && test->start == 0) { +#if __GNUC_PREREQ (10, 0) && !__GNUC_PREREQ (11, 0) + DIAG_PUSH_NEEDS_COMMENT; + /* Avoid GCC 10 false positive warning: specified size exceeds maximum + object size. */ + DIAG_IGNORE_NEEDS_COMMENT (10, "-Wstringop-overflow"); +#endif res = re_search (®buf, test->string, strlen (test->string), test->res, strlen (test->string) - test->res, NULL); +#if __GNUC_PREREQ (10, 0) && !__GNUC_PREREQ (11, 0) + DIAG_POP_NEEDS_COMMENT; +#endif if (res != test->res) { printf ("%sre_search from expected \"%s\" \"%s\" failed: %d (expected %d)\n",