From patchwork Fri Jul 12 20:48:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1960020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLNwz5KSJz1xpd for ; Sat, 13 Jul 2024 06:48:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3C5C3858433 for ; Fri, 12 Jul 2024 20:48:49 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id C116438313AC for ; Fri, 12 Jul 2024 20:48:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C116438313AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C116438313AC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817309; cv=none; b=qebkLIIDy4ScDNtRJII8aBgx9gWAM8GKIQX714yoas4tLyB0CBvVtyjVfCqyTT/Bk9oZe6JKM8QpH5N1tWZgKTIWgjR7/4vrOXcbY6rTAE4DcKZXzxO7OJSsUCNXn5Rx0axA28E9PFJTZBPHNuA+08KG9EsEfKptu4AjDmNwEgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817309; c=relaxed/simple; bh=zEYGOSKSOI73wCWDo24y1KuOYCnK/zmSI5WzkOioOOM=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=dfPM80ec3ZcpstB8B6MUz+WwMpHRqzxTpnutsgEXU6dyIITrSJvkIfv5QZHbbSGIwmY9WCkwkpWLU/SkpyOz3qY9j2CBPuKj05yddpLzwLILjIiSSn3QqOQVXf5TllRCoR7iPCFmcp/QtP7FYMFzNMy6n7eEKDgP9d7ViSAd6SY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 4EAAE92009C; Fri, 12 Jul 2024 22:48:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 4A19E92009B; Fri, 12 Jul 2024 21:48:27 +0100 (BST) Date: Fri, 12 Jul 2024 21:48:27 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v5 1/4] nptl: Use facilities in tst-setuid3 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.6 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Remove local FAIL macro in favor to FAIL_EXIT1 from , which provides equivalent reporting, with the name of the file and the line number within of the failure site additionally included. Remove FAIL_ERR altogether and include ": %m" explicitly with the format string supplied to FAIL_EXIT1 as there seems little value to have a separate macro just for this. --- New change in v5. --- sysdeps/pthread/tst-setuid3.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) glibc-tst-setuid3-fail-ret-exit1.diff Index: glibc/sysdeps/pthread/tst-setuid3.c =================================================================== --- glibc.orig/sysdeps/pthread/tst-setuid3.c +++ glibc/sysdeps/pthread/tst-setuid3.c @@ -15,24 +15,19 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include #include +#include + /* The test must run under a non-privileged user ID. */ static const uid_t test_uid = 1; static pthread_barrier_t barrier1; static pthread_barrier_t barrier2; -#define FAIL(fmt, ...) \ - do { printf ("FAIL: " fmt "\n", __VA_ARGS__); _exit (1); } while (0) - -#define FAIL_ERR(fmt, ...) \ - do { printf ("FAIL: " fmt ": %m\n", __VA_ARGS__); _exit (1); } while (0) - /* True if x is not a successful return code from pthread_barrier_wait. */ static inline bool is_invalid_barrier_ret (int x) @@ -45,10 +40,10 @@ thread_func (void *ctx __attribute__ ((u { int ret = pthread_barrier_wait (&barrier1); if (is_invalid_barrier_ret (ret)) - FAIL ("pthread_barrier_wait (barrier1) (on thread): %d", ret); + FAIL_EXIT1 ("pthread_barrier_wait (barrier1) (on thread): %d", ret); ret = pthread_barrier_wait (&barrier2); if (is_invalid_barrier_ret (ret)) - FAIL ("pthread_barrier_wait (barrier2) (on thread): %d", ret); + FAIL_EXIT1 ("pthread_barrier_wait (barrier2) (on thread): %d", ret); return NULL; } @@ -59,13 +54,13 @@ setuid_failure (int phase) switch (ret) { case 0: - FAIL ("setuid succeeded unexpectedly in phase %d", phase); + FAIL_EXIT1 ("setuid succeeded unexpectedly in phase %d", phase); case -1: if (errno != EPERM) - FAIL_ERR ("setuid phase %d", phase); + FAIL_EXIT1 ("setuid phase %d: %m", phase); break; default: - FAIL ("invalid setuid return value in phase %d: %d", phase, ret); + FAIL_EXIT1 ("invalid setuid return value in phase %d: %d", phase, ret); } } @@ -74,42 +69,42 @@ do_test (void) { if (getuid () == 0) if (setuid (test_uid) != 0) - FAIL_ERR ("setuid (%u)", (unsigned) test_uid); + FAIL_EXIT1 ("setuid (%u): %m", (unsigned) test_uid); if (setuid (getuid ())) - FAIL_ERR ("setuid (%s)", "getuid ()"); + FAIL_EXIT1 ("setuid (%s): %m", "getuid ()"); setuid_failure (1); int ret = pthread_barrier_init (&barrier1, NULL, 2); if (ret != 0) - FAIL ("pthread_barrier_init (barrier1): %d", ret); + FAIL_EXIT1 ("pthread_barrier_init (barrier1): %d", ret); ret = pthread_barrier_init (&barrier2, NULL, 2); if (ret != 0) - FAIL ("pthread_barrier_init (barrier2): %d", ret); + FAIL_EXIT1 ("pthread_barrier_init (barrier2): %d", ret); pthread_t thread; ret = pthread_create (&thread, NULL, thread_func, NULL); if (ret != 0) - FAIL ("pthread_create: %d", ret); + FAIL_EXIT1 ("pthread_create: %d", ret); /* Ensure that the thread is running properly. */ ret = pthread_barrier_wait (&barrier1); if (is_invalid_barrier_ret (ret)) - FAIL ("pthread_barrier_wait (barrier1): %d", ret); + FAIL_EXIT1 ("pthread_barrier_wait (barrier1): %d", ret); setuid_failure (2); /* Check success case. */ if (setuid (getuid ()) != 0) - FAIL_ERR ("setuid (%s)", "getuid ()"); + FAIL_EXIT1 ("setuid (%s): %m", "getuid ()"); /* Shutdown. */ ret = pthread_barrier_wait (&barrier2); if (is_invalid_barrier_ret (ret)) - FAIL ("pthread_barrier_wait (barrier2): %d", ret); + FAIL_EXIT1 ("pthread_barrier_wait (barrier2): %d", ret); ret = pthread_join (thread, NULL); if (ret != 0) - FAIL ("pthread_join: %d", ret); + FAIL_EXIT1 ("pthread_join: %d", ret); return 0; } From patchwork Fri Jul 12 20:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1960023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLNxz3DmTz1xpd for ; Sat, 13 Jul 2024 06:49:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CB043831252 for ; Fri, 12 Jul 2024 20:49:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 9C559383125C for ; Fri, 12 Jul 2024 20:48:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C559383125C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C559383125C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817317; cv=none; b=FGmrZPp8aBKJnaF0wb80I3XSbzehJUasoBk6+bq65TIwL7evvKHGps9jTnCHwcIVFDsl6t3kdRWWwi6o5sI6cIjCUi/L3i5O23FnBYah1RRWV6DeSgnVexYnF43H9cGaRna97TPoNkymtQPdD99SChBJD6CTMG5OzEFg38GL/T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817317; c=relaxed/simple; bh=Dt2WaslfyxRCQtzfKth+ZyZkvnhg4AHY7q8hCivEKOs=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=eg8CpRpI81tvdxPTha9iWJIfmn3mlXlRDqlvfrq1K8jFOeRqsFf0v9ZMrxtxZl7bLSFZ60VSIfj+6TxvArLVaVNoJZSlZlcMmJKLvWawKIU6OJLX/oWm2R5piWzMFqiNfto6P88v4NNPwijQerc7zR7Bis8KajLZOcgLP54Z7Ro= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id D53F292009C; Fri, 12 Jul 2024 22:48:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id D0BF292009B; Fri, 12 Jul 2024 21:48:33 +0100 (BST) Date: Fri, 12 Jul 2024 21:48:33 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v5 2/4] posix: Use facilities in tst-truncate and tst-truncate64 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Remove local FAIL macro in favor to FAIL_RET from , which provides equivalent reporting, with the name of the file of the failure site additionally included, for the tst-truncate-common core shared between the tst-truncate and tst-truncate64 tests. --- New change in v5. --- posix/tst-truncate-common.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) glibc-tst-truncate-common-fail-ret-exit1.diff Index: glibc/posix/tst-truncate-common.c =================================================================== --- glibc.orig/posix/tst-truncate-common.c +++ glibc/posix/tst-truncate-common.c @@ -21,6 +21,8 @@ #include #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -42,9 +44,6 @@ do_prepare (void) } } -#define FAIL(str) \ - do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0) - static int do_test_with_offset (off_t offset) { @@ -54,35 +53,35 @@ do_test_with_offset (off_t offset) memset (buf, 0xcf, sizeof (buf)); if (pwrite (temp_fd, buf, sizeof (buf), offset) != sizeof (buf)) - FAIL ("write failed"); + FAIL_RET ("write failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + sizeof (buf))) - FAIL ("initial size wrong"); + FAIL_RET ("initial size wrong"); if (ftruncate (temp_fd, offset + 800) < 0) - FAIL ("size reduction with ftruncate failed"); + FAIL_RET ("size reduction with ftruncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800)) - FAIL ("size after reduction with ftruncate is incorrect"); + FAIL_RET ("size after reduction with ftruncate is incorrect"); /* The following test covers more than POSIX. POSIX does not require that ftruncate() can increase the file size. But we are testing Unix systems. */ if (ftruncate (temp_fd, offset + 1200) < 0) - FAIL ("size increate with ftruncate failed"); + FAIL_RET ("size increate with ftruncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200)) - FAIL ("size after increase is incorrect"); + FAIL_RET ("size after increase is incorrect"); if (truncate (temp_filename, offset + 800) < 0) - FAIL ("size reduction with truncate failed"); + FAIL_RET ("size reduction with truncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 800)) - FAIL ("size after reduction with truncate incorrect"); + FAIL_RET ("size after reduction with truncate incorrect"); /* The following test covers more than POSIX. POSIX does not require that truncate() can increase the file size. But we are testing Unix systems. */ if (truncate (temp_filename, (offset + 1200)) < 0) - FAIL ("size increase with truncate failed"); + FAIL_RET ("size increase with truncate failed"); if (fstat (temp_fd, &st) < 0 || st.st_size != (offset + 1200)) - FAIL ("size increase with truncate is incorrect"); + FAIL_RET ("size increase with truncate is incorrect"); return 0; } From patchwork Fri Jul 12 20:48:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1960021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLNxJ2rl3z1xpd for ; Sat, 13 Jul 2024 06:49:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39DE3383125D for ; Fri, 12 Jul 2024 20:49:06 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id C43F238319FD for ; Fri, 12 Jul 2024 20:48:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C43F238319FD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C43F238319FD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817325; cv=none; b=hFVNhMB3VaWSXWIclqHtlHirIlWgXktTuVq07mgR4zQQVC7f3d0DTkFcgRhazuNU4QYLspQO6zCpUJHl/x84acVLqlXdghA1D3yQzfpotp+D/AItFFqRqa84xcU6aroFDYedYCwzwxmmPmCA7RJn0kt+CQ7a/EObn5lVzPF51Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817325; c=relaxed/simple; bh=SVLjfyrznSPlS3WsX7DdbG5WsqhnwaxyL1xMsWucbxs=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=wq/KE1E1Ar6Nb6pys9yAEiFeFUHdCsPdVIm0F58S/LaVYAi/GW+R+GzuK/CNXUpwYJQgbHtOJ7A1WQibD2RxcWySnuzST6XR3q/k/JRPVF5kpxYJLVGFJr2H4YiWID98Z5ljEfGNg+T3kAOJ6q2LF6LoY2vYg0l4Guq84vEBUaA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 55CE292009C; Fri, 12 Jul 2024 22:48:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 4F2D192009B; Fri, 12 Jul 2024 21:48:42 +0100 (BST) Date: Fri, 12 Jul 2024 21:48:42 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v5 3/4] support: Add FAIL test failure helper In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.9 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Add a FAIL test failure helper analogous to FAIL_RET, that does not cause the current function to return, providing a standardized way to report a test failure with a message supplied while permitting the caller to continue executing, for further reporting, cleaning up, etc. Update existing test cases that provide a conflicting definition of FAIL by removing the local FAIL definition and then as follows: - tst-fortify-syslog: provide a meaningful message in addition to the file name already added by ; 'support_record_failure' is already called by 'support_print_failure_impl' invoked by the new FAIL test failure helper. - tst-ctype: no update to FAIL calls required, with the name of the file and the line number within of the failure site additionally included by the new FAIL test failure helper, and error counting plus count reporting upon test program termination also already provided by 'support_record_failure' and 'support_report_failure' respectively, called by 'support_print_failure_impl' and 'adjust_exit_status' also respectively. However in a number of places 'printf' is called and the error count adjusted by hand, so update these places to make use of FAIL instead. And last but not least adjust the final summary just to report completion, with any error count following as reported by the test driver. - test-tgmath2: no update to FAIL calls required, with the name of the file of the failure site additionally included by the new FAIL test failure helper. Also there is no need to track the return status by hand as any call to FAIL will eventually cause the test case to return an unsuccesful exit status regardless of the return status from the test function, via a call to 'adjust_exit_status' made by the test driver. --- Hi, I have verified, by inducing errors by hand across all three test cases affected, that replacement error reporting is at least equivalent to original one and that the return status is correct. Given the nature of the change all the test cases, even though independent from each other and the change to , need to go in as a single commit so as to avoid transient regressions, which could then adversely affect bisection in the future. Maciej Changes from v4: - Remove local FAIL macro definitions from tst-fortify-syslog, tst-ctype, and test-tgmath2, adjusting call sites to make use of the macro now provided by . No change from v3. New change in v3. --- debug/tst-fortify-syslog.c | 8 +------- localedata/tst-ctype.c | 40 +++++++++------------------------------- math/test-tgmath2.c | 13 +++---------- support/check.h | 5 +++++ 4 files changed, 18 insertions(+), 48 deletions(-) glibc-support-check-fail.diff Index: glibc/debug/tst-fortify-syslog.c =================================================================== --- glibc.orig/debug/tst-fortify-syslog.c +++ glibc/debug/tst-fortify-syslog.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -46,18 +45,13 @@ handler (int sig) _exit (127); } -#define FAIL() \ - do { \ - printf ("Failure on line %d\n", __LINE__); \ - support_record_failure (); \ - } while (0) #define CHK_FAIL_START \ chk_fail_ok = 1; \ if (! setjmp (chk_fail_buf)) \ { #define CHK_FAIL_END \ chk_fail_ok = 0; \ - FAIL (); \ + FAIL ("not supposed to reach here"); \ } static void Index: glibc/localedata/tst-ctype.c =================================================================== --- glibc.orig/localedata/tst-ctype.c +++ glibc/localedata/tst-ctype.c @@ -21,6 +21,8 @@ #include #include +#include + static const char lower[] = "abcdefghijklmnopqrstuvwxyz"; static const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -53,19 +55,11 @@ static struct classes #define nclasses (sizeof (classes) / sizeof (classes[0])) -#define FAIL(str, args...) \ - { \ - printf (" " str "\n", ##args); \ - ++errors; \ - } - - static int do_test (void) { const char *cp; const char *cp2; - int errors = 0; char *inpline = NULL; size_t inplinelen = 0; char *resline = NULL; @@ -394,11 +388,8 @@ punct = %04x alnum = %04x\n", { if (((__ctype_b[(unsigned int) *inp] & classes[n].mask) != 0) != (*resp != '0')) - { - printf (" is%s('%c' = '\\x%02x') %s true\n", inpline, - *inp, *inp, *resp == '1' ? "not" : "is"); - ++errors; - } + FAIL (" is%s('%c' = '\\x%02x') %s true\n", inpline, + *inp, *inp, *resp == '1' ? "not" : "is"); ++inp; ++resp; } @@ -408,11 +399,8 @@ punct = %04x alnum = %04x\n", while (*inp != '\0') { if (tolower (*inp) != *resp) - { - printf (" tolower('%c' = '\\x%02x') != '%c'\n", - *inp, *inp, *resp); - ++errors; - } + FAIL (" tolower('%c' = '\\x%02x') != '%c'\n", + *inp, *inp, *resp); ++inp; ++resp; } @@ -422,11 +410,8 @@ punct = %04x alnum = %04x\n", while (*inp != '\0') { if (toupper (*inp) != *resp) - { - printf (" toupper('%c' = '\\x%02x') != '%c'\n", - *inp, *inp, *resp); - ++errors; - } + FAIL (" toupper('%c' = '\\x%02x') != '%c'\n", + *inp, *inp, *resp); ++inp; ++resp; } @@ -436,14 +421,7 @@ punct = %04x alnum = %04x\n", } - if (errors != 0) - { - printf (" %d error%s for `%s' locale\n\n\n", errors, - errors == 1 ? "" : "s", setlocale (LC_ALL, NULL)); - return 1; - } - - printf (" No errors for `%s' locale\n\n\n", setlocale (LC_ALL, NULL)); + printf ("Completed testing for `%s' locale\n\n\n", setlocale (LC_ALL, NULL)); return 0; } Index: glibc/math/test-tgmath2.c =================================================================== --- glibc.orig/math/test-tgmath2.c +++ glibc/math/test-tgmath2.c @@ -24,6 +24,8 @@ #include #include +#include + //#define DEBUG typedef complex float cfloat; @@ -87,13 +89,6 @@ enum int count; int counts[Tlast][C_last]; -#define FAIL(str) \ - do \ - { \ - printf ("%s failure on line %d\n", (str), __LINE__); \ - result = 1; \ - } \ - while (0) #define TEST_TYPE_ONLY(expr, rettype) \ do \ { \ @@ -133,8 +128,6 @@ int counts[Tlast][C_last]; int test_cos (const int Vint4, const long long int Vllong4) { - int result = 0; - TEST (cos (vfloat1), float, cos); TEST (cos (vdouble1), double, cos); TEST (cos (vldouble1), ldouble, cos); @@ -152,7 +145,7 @@ test_cos (const int Vint4, const long lo TEST (cos (Vcdouble1), cdouble, cos); TEST (cos (Vcldouble1), cldouble, cos); - return result; + return 0; } int Index: glibc/support/check.h =================================================================== --- glibc.orig/support/check.h +++ glibc/support/check.h @@ -25,6 +25,11 @@ __BEGIN_DECLS /* Record a test failure, print the failure message to standard output + and pass the result of 1 through. */ +#define FAIL(...) \ + support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__) + +/* Record a test failure, print the failure message to standard output and return 1. */ #define FAIL_RET(...) \ return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__) From patchwork Fri Jul 12 20:48:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1960022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLNxR6lfYz1xpd for ; Sat, 13 Jul 2024 06:49:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3E9B3830B40 for ; Fri, 12 Jul 2024 20:49:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id A6AFC3831263 for ; Fri, 12 Jul 2024 20:48:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6AFC3831263 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A6AFC3831263 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817335; cv=none; b=yDqdG7y9s1s6fs56YB0+bnuuWXtlcDqJChdTl1SO+OkdigadUToeZgBxPRdIsQKF0WNegpDyo2IbcxC8f9pJYYX/PnWXZTNmIeYwYPlYIbLOGuedlaMDHjUxQtinSa4wZHMp/RI6brFrR/Q12iufFYxrJQB66Veco2LZTlhiLKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720817335; c=relaxed/simple; bh=x10Fs+BpuxFFHWed9ALI8cAu+Qcp6WfZ/2BI80TBMGE=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=DLLhdD8gqp2LeQ33ffNxyFkhLiq0QEqaFl+Wxy5MDZrPVIZ6n7p1Np8TD4CE4CXBwAJztLhE+DXhKL7Vl0YS5V2QVD75L9MiFLvBd3AsIOSLQOccugnxxqTRNVyFR0MriwvIJmxpyAxZTOeEQ3Nps4Drha1UaAtdNyYIVew4x9I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 3360592009C; Fri, 12 Jul 2024 22:48:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 2FFE092009B; Fri, 12 Jul 2024 21:48:53 +0100 (BST) Date: Fri, 12 Jul 2024 21:48:53 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v5 4/4] stdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.6 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org From: Maciej W. Rozycki Complement commit b03e4d7bd25b ("stdio: fix vfscanf with matches longer than INT_MAX (bug 27650)") and add a test case for the issue, inspired by the reproducer provided with the bug report. This has been verified to succeed as from the commit referred and fail beforehand. As the test requires 2GiB of data to be passed around its performance has been evaluated using a choice of systems and the execution time determined to be respectively in the range of 9s for POWER9@2.166GHz, 24s for FU740@1.2GHz, and 40s for 74Kf@950MHz. As this is on the verge of and beyond the default timeout it has been increased by the factor of 8. Regardless, following recent practice the test has been added to the standard rather than extended set. --- Changes from v4: - Discard return status tracking, having observed that any call to FAIL will cause the test case to exit unsuccessfully owing to a call to `adjust_exit_status' made by the test driver just before termination. - Remove an extraneous `/' from LD_PRELOAD definition. Changes from v3: - Add tst-scanf-bz27650-ENV setting for `mtrace'. Changes from v2: - Rework error reporting in terms of . - Handle the error condition for `fgetc' analogously to `fscanf'. - Improve the error message for the EOF condition for both functions. - Call `fclose' before termination where appropriate. Changes from v1: - Reimplement in terms of `fopencookie', eliminating the need for a subprocess and associated handling. - Update execution times reported in the change description, slightly reduced accordingly. - Correct error handling for `fscanf'. - Fix a typo s/MAX_INT/INT_MAX/ in comments. --- stdio-common/Makefile | 5 + stdio-common/tst-scanf-bz27650.c | 108 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) glibc-tst-scanf-bz27650.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -244,6 +244,7 @@ tests := \ tst-scanf-binary-c23 \ tst-scanf-binary-gnu11 \ tst-scanf-binary-gnu89 \ + tst-scanf-bz27650 \ tst-scanf-intn \ tst-scanf-round \ tst-scanf-to_inpunct \ @@ -314,6 +315,7 @@ generated += \ tst-printf-fp-free.mtrace \ tst-printf-fp-leak-mem.out \ tst-printf-fp-leak.mtrace \ + tst-scanf-bz27650.mtrace \ tst-vfprintf-width-prec-mem.out \ tst-vfprintf-width-prec.mtrace \ # generated @@ -403,6 +405,9 @@ tst-printf-fp-free-ENV = \ tst-printf-fp-leak-ENV = \ MALLOC_TRACE=$(objpfx)tst-printf-fp-leak.mtrace \ LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so +tst-scanf-bz27650-ENV = \ + MALLOC_TRACE=$(objpfx)tst-scanf-bz27650.mtrace \ + LD_PRELOAD=$(common-objpfx)malloc/libc_malloc_debug.so $(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ Index: glibc/stdio-common/tst-scanf-bz27650.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-scanf-bz27650.c @@ -0,0 +1,108 @@ +/* Test for BZ #27650, formatted input matching beyond INT_MAX. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +/* Produce a stream of more than INT_MAX characters via buffer BUF of + size SIZE according to bookkeeping in COOKIE and then return EOF. */ + +static ssize_t +io_read (void *cookie, char *buf, size_t size) +{ + unsigned int *written = cookie; + unsigned int w = *written; + + if (w > INT_MAX) + return 0; + + memset (buf, 'a', size); + *written = w + size; + return size; +} + +/* Consume a stream of more than INT_MAX characters from an artificial + input stream of which none is the new line character. The call to + fscanf is supposed to complete upon the EOF condition of input, + however in the presence of BZ #27650 it will terminate prematurely + with characters still outstanding in input. Diagnose the condition + and return status accordingly. */ + +int +do_test (void) +{ + static cookie_io_functions_t io_funcs = { .read = io_read }; + unsigned int written = 0; + FILE *in; + int v; + + mtrace (); + + in = fopencookie (&written, "r", io_funcs); + if (in == NULL) + { + FAIL ("fopencookie: %m"); + goto out; + } + + v = fscanf (in, "%*[^\n]"); + if (ferror (in)) + { + FAIL ("fscanf: input failure, at %u: %m", written); + goto out_close; + } + else if (v == EOF) + { + FAIL ("fscanf: unexpected end of file, at %u", written); + goto out_close; + } + + if (!feof (in)) + { + v = fgetc (in); + if (ferror (in)) + FAIL ("fgetc: input failure: %m"); + else if (v == EOF) + FAIL ("fgetc: unexpected end of file after missing end of file"); + else if (v == '\n') + FAIL ("unexpected new line character received"); + else + FAIL ("character received after end of file expected: \\x%02x", v); + } + +out_close: + if (fclose (in) != 0) + FAIL ("fclose: %m"); + +out: + return EXIT_SUCCESS; +} + +#define TIMEOUT (DEFAULT_TIMEOUT * 8) +#include