From patchwork Thu Jul 4 12:59:47 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: 1956882 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 4WFGvw5qQPz1xqq for ; Thu, 4 Jul 2024 23:00:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BC78384A476 for ; Thu, 4 Jul 2024 13:00:11 +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 2CD5A384A443 for ; Thu, 4 Jul 2024 12:59:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CD5A384A443 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 2CD5A384A443 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=1720097989; cv=none; b=Uq/B0lzbYaWUn/3FyggB6D7qyergRsHsyM7AnKw65IjHf0J46GBnEiWLsIk3aA07rTTb6A/+YKbhP7jXP80DRjshtrW5hA+9uWR2HDR6XTtKwaQrdiqc/5FpZaqT+XqsAsnv4mciCI1ChX8aN6mS6McRyJyeHw4sKBJS9lkPTDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720097989; c=relaxed/simple; bh=6VS3mzWLJgJyjAeXmsDcLrz8iHu6bNI6DCxMfQsMDWg=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=hvK4M69+3s6xXpoRdsyiCbZ1k0ZhDsml+sDcoCR1qkI2KIW8DSkBjSpbwWp+e+sh38g3HHjzg1XuwY7Rw11KtqGKxIQRAFfM7pR3SdEgL7V20QLRkyI8WvxTF4Gz7uwvlNpHQh4EYh548vrPoGXi0+TMtVvuncBIwwYG2/YG8i8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id ACF4B92009C; Thu, 4 Jul 2024 14:59:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id A926D92009B; Thu, 4 Jul 2024 13:59:47 +0100 (BST) Date: Thu, 4 Jul 2024 13:59:47 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v4 1/2] 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=-1163.1 required=5.0 tests=BAYES_00, 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. --- No change from v3. New change in v3. --- support/check.h | 5 +++++ 1 file changed, 5 insertions(+) glibc-support-check-fail.diff 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 Thu Jul 4 12:59:59 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: 1956883 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 4WFGws1JG4z1xqs for ; Thu, 4 Jul 2024 23:01:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A305384A46E for ; Thu, 4 Jul 2024 13:00:59 +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 DD3D2384A44C for ; Thu, 4 Jul 2024 12:59:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD3D2384A44C 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 DD3D2384A44C 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=1720098002; cv=none; b=jmERmbXPJrhspHGox9aG78XIjYnGmPDfcfKBnNx5UWBAwWLSGnAcgA0roX89W3NSEL8fvpB6gOG8tP5CI9HG1+jXe/DynGAHMdgfGr8Xk5/Hr3/HHS4soSaecoY5JYlGiytQmjkKw7YIRoLdRlHa+4q3k8CYhuVDptYvpQoagM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720098002; c=relaxed/simple; bh=lOXKXLSf1g1WIGgGVGXvmvGcl33zGcsUAwaENKnb230=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=iJ09AndxsUZXxDFgjw19K7fIe4PGScpBt4zJSuhIz2h5AAreUN9CgCJaVxA//ewFFSlbOmbcrAlxmbJ3X84h3OwrtuJceKd6TRysvKiKHM74YEjlsMnvRT3Bo7jnOkIz40+PxrQbYuB7K5eH5IxgxJimIm2+HUTDtPAebcJWbdI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 6192A92009C; Thu, 4 Jul 2024 14:59:59 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 5DD2792009B; Thu, 4 Jul 2024 13:59:59 +0100 (BST) Date: Thu, 4 Jul 2024 13:59:59 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v4 2/2] 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=-3487.9 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 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 | 109 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 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,109 @@ +/* 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; + int s = EXIT_SUCCESS; + FILE *in; + int v; + + mtrace (); + + in = fopencookie (&written, "r", io_funcs); + if (in == NULL) + { + s = FAIL ("fopencookie: %m"); + goto out; + } + + v = fscanf (in, "%*[^\n]"); + if (ferror (in)) + { + s = FAIL ("fscanf: input failure, at %u: %m", written); + goto out_close; + } + else if (v == EOF) + { + s = FAIL ("fscanf: unexpected end of file, at %u", written); + goto out_close; + } + + if (!feof (in)) + { + v = fgetc (in); + if (ferror (in)) + s = FAIL ("fgetc: input failure: %m"); + else if (v == EOF) + s = FAIL ("fgetc: unexpected end of file after missing end of file"); + else if (v == '\n') + s = FAIL ("unexpected new line character received"); + else + s = FAIL ("character received after end of file expected: \\x%02x", v); + } + +out_close: + if (fclose (in) != 0) + s = FAIL ("fclose: %m"); + +out: + return s; +} + +#define TIMEOUT (DEFAULT_TIMEOUT * 8) +#include