From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com [IPv6:2607:f8b0:4864:20::92b]) by sourceware.org (Postfix) with ESMTPS id 9955F3858419 for ; Wed, 20 Oct 2021 12:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9955F3858419 Received: by mail-ua1-x92b.google.com with SMTP id f4so6133211uad.4 for ; Wed, 20 Oct 2021 05:06:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=KvW4rG2fkNXeyBALVaaLDkFrmF9QPAwgXrSuiBIn6ig=; b=3BfrypZJylUPf8vBeFq27BqrxlWbDfqRr7cP8xwz8NLWIQoxMOoa8LL8nrkWbQsXqd xJRA/ypZHt7L5cQWbBGdkTdSaNOIbupMcok392AL5/Rh2yAq4PMZfMLqaO7GyddIF42y 8Cg+FdX2VjbHenTVnegk9O/o0rIu/GYnSy5cXhIWmhzzyC3jPdEP9gOuiPqE5pQ9XSED 6iJfnmf6UplFaEyiQn4ch2CTm/GewB0I/0gabNI60fUCJgCQ3W/pMFJMjFPbOE+B1kWB C4I5P9bMNZIt0XL8VozigQRj5TjpWWG05U9mdndeUfZ/PX5T52TGk7U1nk7mNVq1LhuE bd+g== X-Gm-Message-State: AOAM533OCa+wTQntTvLseoXb0k/sZzbGNU0oliK+owQlvobX6EQjhWg6 8uNlW8ZpAXY+XTyfjSTxUjCPrLsHseg= X-Google-Smtp-Source: ABdhPJz3WkBjWbytbnYvbOjXTmOBZK42LhlaYVtTlRozQboG3tdUCj7tDzBLLddIP+F2Esy+ZDcFPg== X-Received: by 2002:a67:32d6:: with SMTP id y205mr41957269vsy.59.1634731578471; Wed, 20 Oct 2021 05:06:18 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:2654:6d0a:89c6:4739:ceb5? ([2804:431:c7ca:2654:6d0a:89c6:4739:ceb5]) by smtp.gmail.com with ESMTPSA id r3sm1123495vsi.23.2021.10.20.05.06.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Oct 2021 05:06:18 -0700 (PDT) Message-ID: <1af8f68d-7ac2-e342-83cd-7ffd434907c0@linaro.org> Date: Wed, 20 Oct 2021 09:06:16 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH v2 2/2] debug: Add tests for _FORTIFY_SOURCE=3 Content-Language: en-US To: Siddhesh Poyarekar , libc-alpha@sourceware.org References: <20211012161629.302696-1-siddhesh@sourceware.org> <20211020052434.1221167-1-siddhesh@sourceware.org> <20211020052434.1221167-3-siddhesh@sourceware.org> From: Adhemerval Zanella In-Reply-To: <20211020052434.1221167-3-siddhesh@sourceware.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 20 Oct 2021 12:06:21 -0000 On 20/10/2021 02:24, Siddhesh Poyarekar wrote: > Add some testing coverage for _FORTIFY_SOURCE=3. > > Signed-off-by: Siddhesh Poyarekar LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > debug/Makefile | 13 ++++-- > debug/tst-chk1.c | 102 +++++++++++++++++++++++++--------------------- > debug/tst-chk7.c | 2 + > debug/tst-chk8.cc | 2 + > 4 files changed, 69 insertions(+), 50 deletions(-) > create mode 100644 debug/tst-chk7.c > create mode 100644 debug/tst-chk8.cc > > diff --git a/debug/Makefile b/debug/Makefile > index 6893111cbf..357f888246 100644 > --- a/debug/Makefile > +++ b/debug/Makefile > @@ -120,6 +120,8 @@ CFLAGS-tst-chk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-chk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-chk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-chk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error > +CFLAGS-tst-chk7.c += -Wno-format -Wno-deprecated-declarations -Wno-error > +CFLAGS-tst-chk8.cc += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-lfschk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-lfschk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error > CFLAGS-tst-lfschk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error > @@ -129,6 +131,7 @@ CFLAGS-tst-lfschk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error > LDLIBS-tst-chk4 = -lstdc++ > LDLIBS-tst-chk5 = -lstdc++ > LDLIBS-tst-chk6 = -lstdc++ > +LDLIBS-tst-chk8 = -lstdc++ > LDLIBS-tst-lfschk4 = -lstdc++ > LDLIBS-tst-lfschk5 = -lstdc++ > LDLIBS-tst-lfschk6 = -lstdc++ > @@ -150,16 +153,16 @@ CFLAGS-tst-ssp-1.c += -fstack-protector-all > > tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \ > tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \ > - tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \ > - tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 tst-backtrace4 \ > - tst-backtrace5 tst-backtrace6 > + tst-chk4 tst-chk5 tst-chk6 tst-chk7 tst-chk8 tst-lfschk4 tst-lfschk5 \ > + tst-lfschk6 tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 \ > + tst-backtrace4 tst-backtrace5 tst-backtrace6 > > ifeq ($(have-ssp),yes) > tests += tst-ssp-1 > endif > > ifeq (,$(CXX)) > -tests-unsupported = tst-chk4 tst-chk5 tst-chk6 \ > +tests-unsupported = tst-chk4 tst-chk5 tst-chk6 tst-chk8 \ > tst-lfschk4 tst-lfschk5 tst-lfschk6 > endif > > @@ -193,6 +196,8 @@ $(objpfx)tst-chk3.out: $(gen-locales) > $(objpfx)tst-chk4.out: $(gen-locales) > $(objpfx)tst-chk5.out: $(gen-locales) > $(objpfx)tst-chk6.out: $(gen-locales) > +$(objpfx)tst-chk7.out: $(gen-locales) > +$(objpfx)tst-chk8.out: $(gen-locales) > $(objpfx)tst-lfschk1.out: $(gen-locales) > $(objpfx)tst-lfschk2.out: $(gen-locales) > $(objpfx)tst-lfschk3.out: $(gen-locales) > diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c > index 6712770201..d11e536f87 100644 > --- a/debug/tst-chk1.c > +++ b/debug/tst-chk1.c > @@ -82,8 +82,14 @@ handler (int sig) > _exit (127); > } > > +#if __USE_FORTIFY_LEVEL == 3 > +volatile size_t buf_size = 10; > +#else > char buf[10]; > wchar_t wbuf[10]; > +#define buf_size sizeof (buf) > +#endif > + > volatile size_t l0; > volatile char *p; > volatile wchar_t *wp; > @@ -122,6 +128,10 @@ int num2 = 987654; > static int > do_test (void) > { > +#if __USE_FORTIFY_LEVEL == 3 > + char *buf = (char *) malloc (buf_size); > + wchar_t *wbuf = (wchar_t *) malloc (buf_size * sizeof (wchar_t)); > +#endif > set_fortify_handler (handler); > > struct A { char buf1[9]; char buf2[1]; } a; > @@ -946,93 +956,93 @@ do_test (void) > > rewind (stdin); > > - if (fgets (buf, sizeof (buf), stdin) != buf > + if (fgets (buf, buf_size, stdin) != buf > || memcmp (buf, "abcdefgh\n", 10)) > FAIL (); > - if (fgets (buf, sizeof (buf), stdin) != buf || memcmp (buf, "ABCDEFGHI", 10)) > + if (fgets (buf, buf_size, stdin) != buf || memcmp (buf, "ABCDEFGHI", 10)) > FAIL (); > > rewind (stdin); > > - if (fgets (buf, l0 + sizeof (buf), stdin) != buf > + if (fgets (buf, l0 + buf_size, stdin) != buf > || memcmp (buf, "abcdefgh\n", 10)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (fgets (buf, sizeof (buf) + 1, stdin) != buf) > + if (fgets (buf, buf_size + 1, stdin) != buf) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (fgets (buf, l0 + sizeof (buf) + 1, stdin) != buf) > + if (fgets (buf, l0 + buf_size + 1, stdin) != buf) > FAIL (); > CHK_FAIL_END > #endif > > rewind (stdin); > > - if (fgets_unlocked (buf, sizeof (buf), stdin) != buf > + if (fgets_unlocked (buf, buf_size, stdin) != buf > || memcmp (buf, "abcdefgh\n", 10)) > FAIL (); > - if (fgets_unlocked (buf, sizeof (buf), stdin) != buf > + if (fgets_unlocked (buf, buf_size, stdin) != buf > || memcmp (buf, "ABCDEFGHI", 10)) > FAIL (); > > rewind (stdin); > > - if (fgets_unlocked (buf, l0 + sizeof (buf), stdin) != buf > + if (fgets_unlocked (buf, l0 + buf_size, stdin) != buf > || memcmp (buf, "abcdefgh\n", 10)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (fgets_unlocked (buf, sizeof (buf) + 1, stdin) != buf) > + if (fgets_unlocked (buf, buf_size + 1, stdin) != buf) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (fgets_unlocked (buf, l0 + sizeof (buf) + 1, stdin) != buf) > + if (fgets_unlocked (buf, l0 + buf_size + 1, stdin) != buf) > FAIL (); > CHK_FAIL_END > #endif > > rewind (stdin); > > - if (fread (buf, 1, sizeof (buf), stdin) != sizeof (buf) > + if (fread (buf, 1, buf_size, stdin) != buf_size > || memcmp (buf, "abcdefgh\nA", 10)) > FAIL (); > - if (fread (buf, sizeof (buf), 1, stdin) != 1 > + if (fread (buf, buf_size, 1, stdin) != 1 > || memcmp (buf, "BCDEFGHI\na", 10)) > FAIL (); > > rewind (stdin); > > - if (fread (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) > + if (fread (buf, l0 + 1, buf_size, stdin) != buf_size > || memcmp (buf, "abcdefgh\nA", 10)) > FAIL (); > - if (fread (buf, sizeof (buf), l0 + 1, stdin) != 1 > + if (fread (buf, buf_size, l0 + 1, stdin) != 1 > || memcmp (buf, "BCDEFGHI\na", 10)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (fread (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) > + if (fread (buf, 1, buf_size + 1, stdin) != buf_size + 1) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (fread (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) > + if (fread (buf, buf_size + 1, l0 + 1, stdin) != 1) > FAIL (); > CHK_FAIL_END > #endif > > rewind (stdin); > > - if (fread_unlocked (buf, 1, sizeof (buf), stdin) != sizeof (buf) > + if (fread_unlocked (buf, 1, buf_size, stdin) != buf_size > || memcmp (buf, "abcdefgh\nA", 10)) > FAIL (); > - if (fread_unlocked (buf, sizeof (buf), 1, stdin) != 1 > + if (fread_unlocked (buf, buf_size, 1, stdin) != 1 > || memcmp (buf, "BCDEFGHI\na", 10)) > FAIL (); > > @@ -1047,100 +1057,100 @@ do_test (void) > > rewind (stdin); > > - if (fread_unlocked (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) > + if (fread_unlocked (buf, l0 + 1, buf_size, stdin) != buf_size > || memcmp (buf, "abcdefgh\nA", 10)) > FAIL (); > - if (fread_unlocked (buf, sizeof (buf), l0 + 1, stdin) != 1 > + if (fread_unlocked (buf, buf_size, l0 + 1, stdin) != 1 > || memcmp (buf, "BCDEFGHI\na", 10)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (fread_unlocked (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) > + if (fread_unlocked (buf, 1, buf_size + 1, stdin) != buf_size + 1) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (fread_unlocked (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) > + if (fread_unlocked (buf, buf_size + 1, l0 + 1, stdin) != 1) > FAIL (); > CHK_FAIL_END > #endif > > lseek (fileno (stdin), 0, SEEK_SET); > > - if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1 > + if (read (fileno (stdin), buf, buf_size - 1) != buf_size - 1 > || memcmp (buf, "abcdefgh\n", 9)) > FAIL (); > - if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1 > + if (read (fileno (stdin), buf, buf_size - 1) != buf_size - 1 > || memcmp (buf, "ABCDEFGHI", 9)) > FAIL (); > > lseek (fileno (stdin), 0, SEEK_SET); > > - if (read (fileno (stdin), buf, l0 + sizeof (buf) - 1) != sizeof (buf) - 1 > + if (read (fileno (stdin), buf, l0 + buf_size - 1) != buf_size - 1 > || memcmp (buf, "abcdefgh\n", 9)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (read (fileno (stdin), buf, sizeof (buf) + 1) != sizeof (buf) + 1) > + if (read (fileno (stdin), buf, buf_size + 1) != buf_size + 1) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (read (fileno (stdin), buf, l0 + sizeof (buf) + 1) != sizeof (buf) + 1) > + if (read (fileno (stdin), buf, l0 + buf_size + 1) != buf_size + 1) > FAIL (); > CHK_FAIL_END > #endif > > - if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2) > - != sizeof (buf) - 1 > + if (pread (fileno (stdin), buf, buf_size - 1, buf_size - 2) > + != buf_size - 1 > || memcmp (buf, "\nABCDEFGH", 9)) > FAIL (); > - if (pread (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1 > + if (pread (fileno (stdin), buf, buf_size - 1, 0) != buf_size - 1 > || memcmp (buf, "abcdefgh\n", 9)) > FAIL (); > - if (pread (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3) > - != sizeof (buf) - 1 > + if (pread (fileno (stdin), buf, l0 + buf_size - 1, buf_size - 3) > + != buf_size - 1 > || memcmp (buf, "h\nABCDEFG", 9)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (pread (fileno (stdin), buf, sizeof (buf) + 1, 2 * sizeof (buf)) > - != sizeof (buf) + 1) > + if (pread (fileno (stdin), buf, buf_size + 1, 2 * buf_size) > + != buf_size + 1) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (pread (fileno (stdin), buf, l0 + sizeof (buf) + 1, 2 * sizeof (buf)) > - != sizeof (buf) + 1) > + if (pread (fileno (stdin), buf, l0 + buf_size + 1, 2 * buf_size) > + != buf_size + 1) > FAIL (); > CHK_FAIL_END > #endif > > - if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2) > - != sizeof (buf) - 1 > + if (pread64 (fileno (stdin), buf, buf_size - 1, buf_size - 2) > + != buf_size - 1 > || memcmp (buf, "\nABCDEFGH", 9)) > FAIL (); > - if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1 > + if (pread64 (fileno (stdin), buf, buf_size - 1, 0) != buf_size - 1 > || memcmp (buf, "abcdefgh\n", 9)) > FAIL (); > - if (pread64 (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3) > - != sizeof (buf) - 1 > + if (pread64 (fileno (stdin), buf, l0 + buf_size - 1, buf_size - 3) > + != buf_size - 1 > || memcmp (buf, "h\nABCDEFG", 9)) > FAIL (); > > #if __USE_FORTIFY_LEVEL >= 1 > CHK_FAIL_START > - if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * sizeof (buf)) > - != sizeof (buf) + 1) > + if (pread64 (fileno (stdin), buf, buf_size + 1, 2 * buf_size) > + != buf_size + 1) > FAIL (); > CHK_FAIL_END > > CHK_FAIL_START > - if (pread64 (fileno (stdin), buf, l0 + sizeof (buf) + 1, 2 * sizeof (buf)) > - != sizeof (buf) + 1) > + if (pread64 (fileno (stdin), buf, l0 + buf_size + 1, 2 * buf_size) > + != buf_size + 1) > FAIL (); > CHK_FAIL_END > #endif > @@ -1178,7 +1188,7 @@ do_test (void) > CHK_FAIL2_END > > CHK_FAIL2_START > - snprintf (buf, sizeof (buf), "%3$d\n", 1, 2, 3, 4); > + snprintf (buf, buf_size, "%3$d\n", 1, 2, 3, 4); > CHK_FAIL2_END > > int sp[2]; Ok, it basically just parametrize 'sizeof (buf)'. > diff --git a/debug/tst-chk7.c b/debug/tst-chk7.c > new file mode 100644 > index 0000000000..2a7b323812 > --- /dev/null > +++ b/debug/tst-chk7.c > @@ -0,0 +1,2 @@ > +#define _FORTIFY_SOURCE 3 > +#include "tst-chk1.c" > diff --git a/debug/tst-chk8.cc b/debug/tst-chk8.cc > new file mode 100644 > index 0000000000..2a7b323812 > --- /dev/null > +++ b/debug/tst-chk8.cc > @@ -0,0 +1,2 @@ > +#define _FORTIFY_SOURCE 3 > +#include "tst-chk1.c" > Ok.