From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by sourceware.org (Postfix) with ESMTPS id 6B2E5393A439 for ; Thu, 13 May 2021 17:04:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6B2E5393A439 Received: by mail-qk1-x72b.google.com with SMTP id v8so8206045qkv.1 for ; Thu, 13 May 2021 10:04:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=z1cMldenhbF7yp2yvHBbmj1qxdE514nTsX1gx2ycQdg=; b=UQ11cYUP0pwIkxQALG5Ukll1ZP2pm2TeN3wOz9yH5rQv4RtzFnA/b79XC8I4LLHOFo 5/ylfIcT+N33DR2OTW9m56oTE50UrrY0EXH+jLw9CDgZDjZ0P15SCtOd7IoiWYh1N4m/ umwScx7a1CDPIbIJQBTgnXhr3S7oZ/cfSxIqvT4JKMm1uskJ/yt7JR063adVx9uqNq7P 8+E3d586lbstTWBlRl2CUWyn+ZRUcO6BSjfuPUY46XgvHi86+gDUW+ivkD7XG5B4o6yI MfWcMKjJvfmOb2wihJoaicY7oCcZItC21Ec14skeJtnzdI5OuH5lHP4y9RInlpHgLVAk 5W+w== X-Gm-Message-State: AOAM533a4CAzHEXrnMILVyBsjl8TB745Urbijb+Z8HXAYXTCEhDosQ9Q qLJfgnJhUfXRff4JluBO5cQ= X-Google-Smtp-Source: ABdhPJxdLl6zbSdjNDKCxYPtUbk+q1RUGQ1hJ6rLM0e+pMKcEZRi8XGyJhFJIMm4WR62cYU6qRrSZA== X-Received: by 2002:a37:9c50:: with SMTP id f77mr39414697qke.107.1620925458058; Thu, 13 May 2021 10:04:18 -0700 (PDT) Received: from [192.168.0.41] (71-218-14-121.hlrn.qwest.net. [71.218.14.121]) by smtp.gmail.com with ESMTPSA id f12sm2710879qtj.26.2021.05.13.10.04.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 10:04:17 -0700 (PDT) Subject: Re: [PATCH] Fix stringop-overflow warning in bug-regex19.c. To: Stefan Liebler , libc-alpha@sourceware.org Cc: msebor@redhat.com References: <20210512063345.2269779-1-stli@linux.ibm.com> <051c230f-b7a7-3403-f912-e85ac7bba1b6@gmail.com> From: Martin Sebor Message-ID: Date: Thu, 13 May 2021 11:04:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <051c230f-b7a7-3403-f912-e85ac7bba1b6@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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-List-Received-Date: Thu, 13 May 2021 17:04:20 -0000 On 5/12/21 9:56 AM, Martin Sebor wrote: > On 5/12/21 12:33 AM, Stefan Liebler via Libc-alpha wrote: >> 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. > > This is a false positive caused by the same bug as the one in > nss/makedb.c.  It's fixed in GCC 11 but the whole change is too > intrusive to backport to 10.  I'll see if I can extract just > the fix itself and backport it. I did that in r10-9819. The fix should be in GCC 10.4 if/when it's released. Martin > > Disabling inlining for the test function as a workaround seems > reasonable to me (a comment should probably be added mentioning > why it's being done).  An alternative is to suppress the warning > using #pragma GCC diagnostic (as was done in nss/makedb.c). > > Martin > > >> --- >>   posix/bug-regex19.c | 1 + >>   1 file changed, 1 insertion(+) >> >> diff --git a/posix/bug-regex19.c b/posix/bug-regex19.c >> index 9bbffb17e3..fcae533762 100644 >> --- a/posix/bug-regex19.c >> +++ b/posix/bug-regex19.c >> @@ -251,6 +251,7 @@ static struct test_s >>   }; >>   int >> +__attribute__ ((noinline)) >>   do_one_test (const struct test_s *test, const char *fail) >>   { >>     int res; >> >