From patchwork Mon Jul 8 13:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1957973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Y9Hhigk8; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uLFz3N0k; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Y9Hhigk8; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uLFz3N0k; dkim-atps=neutral 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 4WHm052g5Fz1xpP for ; Mon, 8 Jul 2024 23:57:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81AF43864836 for ; Mon, 8 Jul 2024 13:57:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 1B1743858C66 for ; Mon, 8 Jul 2024 13:57:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B1743858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B1743858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720447028; cv=none; b=kiQpWk2mrGETIwVyG2Itoysel4lJccTGM0I3aNRFwahmVYNaHgdvK52xgCg+cFCVnL2OKA1kq4BpB3kkzExPY+FaC5a99p3mHGqxQ79MEzJ+nOPHZ3DPoF5OosTWSEONXj066zFfhg++12m5yQsbSLfdVT1BqoOfAeSzkXUjYwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720447028; c=relaxed/simple; bh=bnDnlYmHi+G7u5vGp59i1/4V/CKl55xMALuPkWBGb94=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=pprgMCFtDKZ4nWEcTp/oQ5UPEV+Nxgbr9Uo6LDhwbQu9FUBwD1upkiNc35TM3Ydj0wCpJvCOuwwE1Ya7Ps60Ycpslh4VMdUhmsFNxz0ez247lDR6fJtAYS3tgd5C42qFRJBRHbuxc4n+CCZiYtn6M7Lce8sjOiYlEQ/Tj1cXPTc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [IPv6:2a07:de40:a101:3:10:168:4:11]) by smtp-out1.suse.de (Postfix) with ESMTP id 9D13021B2D for ; Mon, 8 Jul 2024 13:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720447025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=7PnKo6eZrDK3BWLKptVMIXNXufKwVChGSNPVhdTgS9I=; b=Y9Hhigk89GYvBnDeFfOXDerYTg4hzRyNSQRBRpoLPK6jyDtz0WzzTlZgM+gwyVb8oTN5no TLZK7EDESKrrBAg6gFIdhp6N+lcymRgwrZau8hAleee6d99VVX0et9JtVLC7AHJSkJZiRr KHGeSRLxMKa5D55FAwCza8OmAKwCq3A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720447025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=7PnKo6eZrDK3BWLKptVMIXNXufKwVChGSNPVhdTgS9I=; b=uLFz3N0kLD+jMTxzFhbXeC23D8I3zVYmOWVZebKTVO6UjgJfYjmRw56a7y4ZUJfAF9g+zo 6A3mSL1Xsw5XeSCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Y9Hhigk8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uLFz3N0k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720447025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=7PnKo6eZrDK3BWLKptVMIXNXufKwVChGSNPVhdTgS9I=; b=Y9Hhigk89GYvBnDeFfOXDerYTg4hzRyNSQRBRpoLPK6jyDtz0WzzTlZgM+gwyVb8oTN5no TLZK7EDESKrrBAg6gFIdhp6N+lcymRgwrZau8hAleee6d99VVX0et9JtVLC7AHJSkJZiRr KHGeSRLxMKa5D55FAwCza8OmAKwCq3A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720447025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=7PnKo6eZrDK3BWLKptVMIXNXufKwVChGSNPVhdTgS9I=; b=uLFz3N0kLD+jMTxzFhbXeC23D8I3zVYmOWVZebKTVO6UjgJfYjmRw56a7y4ZUJfAF9g+zo 6A3mSL1Xsw5XeSCA== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id 8BD594A050D; Mon, 8 Jul 2024 15:57:05 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] libio: handle opening a file when all files are closed (bug 31963) X-Yow: Place me on a BUFFER counter while you BELITTLE several BELLHOPS in the Trianon Room!! Let me one of your SUBSIDIARIES! Date: Mon, 08 Jul 2024 15:57:05 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spamd-Result: default: False [1.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; HFILTER_HOSTNAME_UNKNOWN(2.50)[]; ONCE_RECEIVED(1.20)[]; RDNS_NONE(1.00)[]; HFILTER_HELO_IP_A(1.00)[hawking.nue2.suse.org]; NEURAL_HAM_LONG(-1.00)[-0.997]; HFILTER_HELO_NORES_A_OR_MX(0.30)[hawking.nue2.suse.org]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.990]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DIRECT_TO_MX(0.00)[Gnus/5.13 (Gnus v5.13)]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_TRACE(0.00)[suse.de:+]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,gnu.org:url] X-Spamd-Bar: + X-Rspamd-Queue-Id: 9D13021B2D X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spam-Score: 1.60 X-Rspamd-Action: no action X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org _IO_list_all becomes NULL when all files (including standard files) are closed. --- libio/Makefile | 1 + libio/genops.c | 3 ++- libio/tst-closeall.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 libio/tst-closeall.c diff --git a/libio/Makefile b/libio/Makefile index 82c7e3ef0b..1f7031066c 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -91,6 +91,7 @@ tests = \ tst-bz24051 \ tst-bz24153 \ tst-bz28828 \ + tst-closeall \ tst-eof \ tst-ext \ tst-ext2 \ diff --git a/libio/genops.c b/libio/genops.c index 994ee9c0b1..99f5e80f20 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -119,7 +119,8 @@ _IO_link_in (struct _IO_FILE_plus *fp) if (_IO_vtable_offset ((FILE *) fp) == 0) { fp->file._prevchain = (FILE **) &_IO_list_all; - _IO_list_all->file._prevchain = &fp->file._chain; + if (_IO_list_all != NULL) + _IO_list_all->file._prevchain = &fp->file._chain; } _IO_list_all = fp; #ifdef _IO_MTSAFE_IO diff --git a/libio/tst-closeall.c b/libio/tst-closeall.c new file mode 100644 index 0000000000..34f5246490 --- /dev/null +++ b/libio/tst-closeall.c @@ -0,0 +1,34 @@ +/* Test that opening a file when all files are closed does not crash (bug 31963) + 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 + +static int +do_test (void) +{ + xfclose (stdin); + xfclose (stdout); + xfclose (stderr); + FILE *f = xfopen ("/dev/null", "w"); + fprintf (f, "final\n"); + xfclose (f); + return 0; +} + +#include