From unknown Sat Sep 13 04:54:47 2025 X-Loop: help-debbugs@gnu.org Subject: bug#7370: [PATCH] csplit: diagnose file counter wraparound Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 11 Nov 2010 08:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 7370 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: patch To: 7370@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.128946384131170 (code B ref -1); Thu, 11 Nov 2010 08:24:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Nov 2010 08:24:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGSRs-00086e-Tg for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:24:01 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGSRq-00086Z-F1 for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:23:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGSWR-00042p-4V for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:28:44 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:46791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGSWR-00042l-1O for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:28:43 -0500 Received: from [140.186.70.92] (port=38970 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGSWP-0000Cs-Hx for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGSWN-00042J-MX for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:41 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:38469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGSWN-000423-AJ for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:39 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id F280639E80F2 for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WbuLO8WW0Wut for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 627B839E80DC for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) Message-ID: <4CDBA933.90507@cs.ucla.edu> Date: Thu, 11 Nov 2010 00:28:35 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Spam-Score: -4.6 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) (Ordinarily I guess I'd just install something like this, but since we're near a release I held off. The bug is unlikely in practice.) * src/csplit.c (create_output_file): Detect overflow when the file counter wraps around, and exit with a diagnostic. Formerly the code silently wrapped around and wrote to the wrong file, losing output data. --- src/csplit.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/csplit.c b/src/csplit.c index 531e492..9505076 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -917,19 +917,27 @@ make_filename (unsigned int num) static void create_output_file (void) { - sigset_t oldset; bool fopen_ok; int fopen_errno; output_filename = make_filename (files_created); - /* Create the output file in a critical section, to avoid races. */ - sigprocmask (SIG_BLOCK, &caught_signals, &oldset); - output_stream = fopen (output_filename, "w"); - fopen_ok = (output_stream != NULL); - fopen_errno = errno; - files_created += fopen_ok; - sigprocmask (SIG_SETMASK, &oldset, NULL); + if (files_created == UINT_MAX) + { + fopen_ok = false; + fopen_errno = EOVERFLOW; + } + else + { + /* Create the output file in a critical section, to avoid races. */ + sigset_t oldset; + sigprocmask (SIG_BLOCK, &caught_signals, &oldset); + output_stream = fopen (output_filename, "w"); + fopen_ok = (output_stream != NULL); + fopen_errno = errno; + files_created += fopen_ok; + sigprocmask (SIG_SETMASK, &oldset, NULL); + } if (! fopen_ok) { -- 1.7.2 From unknown Sat Sep 13 04:54:47 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Paul Eggert Subject: bug#7370: closed (Re: bug#7370: [PATCH] csplit: diagnose file counter wraparound) Message-ID: References: <87vcydcky3.fsf@rho.meyering.net> <4CDBA933.90507@cs.ucla.edu> X-Gnu-PR-Message: they-closed 7370 X-Gnu-PR-Package: coreutils X-Gnu-PR-Keywords: patch Reply-To: 7370@debbugs.gnu.org Date: Sun, 17 Apr 2011 09:00:05 +0000 Content-Type: multipart/mixed; boundary="----------=_1303030805-1492-1" This is a multi-part message in MIME format... ------------=_1303030805-1492-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #7370: [PATCH] csplit: diagnose file counter wraparound which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 7370@debbugs.gnu.org. --=20 7370: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D7370 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1303030805-1492-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 7370-done) by debbugs.gnu.org; 17 Apr 2011 08:59:40 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QBNpT-0000NJ-Aa for submit@debbugs.gnu.org; Sun, 17 Apr 2011 04:59:40 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QBNpR-0000N7-MF for 7370-done@debbugs.gnu.org; Sun, 17 Apr 2011 04:59:37 -0400 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 39B5D6012A; Sun, 17 Apr 2011 10:59:32 +0200 (CEST) From: Jim Meyering To: 7370-done@debbugs.gnu.org Subject: Re: bug#7370: [PATCH] csplit: diagnose file counter wraparound In-Reply-To: <4CDBA933.90507@cs.ucla.edu> (Paul Eggert's message of "Thu, 11 Nov 2010 00:28:35 -0800") References: <4CDBA933.90507@cs.ucla.edu> Date: Sun, 17 Apr 2011 10:59:32 +0200 Message-ID: <87vcydcky3.fsf@rho.meyering.net> Lines: 10 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: 7370-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) Paul Eggert wrote: > (Ordinarily I guess I'd just install something like this, but since > we're near a release I held off. The bug is unlikely in practice.) > > * src/csplit.c (create_output_file): Detect overflow when the > file counter wraps around, and exit with a diagnostic. Formerly > the code silently wrapped around and wrote to the wrong file, > losing output data. This was pushed in December. Closing. ------------=_1303030805-1492-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 11 Nov 2010 08:24:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGSRs-00086e-Tg for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:24:01 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PGSRq-00086Z-F1 for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:23:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGSWR-00042p-4V for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:28:44 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:46791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGSWR-00042l-1O for submit@debbugs.gnu.org; Thu, 11 Nov 2010 03:28:43 -0500 Received: from [140.186.70.92] (port=38970 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGSWP-0000Cs-Hx for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGSWN-00042J-MX for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:41 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:38469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGSWN-000423-AJ for bug-coreutils@gnu.org; Thu, 11 Nov 2010 03:28:39 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id F280639E80F2 for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WbuLO8WW0Wut for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 627B839E80DC for ; Thu, 11 Nov 2010 00:28:36 -0800 (PST) Message-ID: <4CDBA933.90507@cs.ucla.edu> Date: Thu, 11 Nov 2010 00:28:35 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: bug-coreutils@gnu.org Subject: [PATCH] csplit: diagnose file counter wraparound Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) (Ordinarily I guess I'd just install something like this, but since we're near a release I held off. The bug is unlikely in practice.) * src/csplit.c (create_output_file): Detect overflow when the file counter wraps around, and exit with a diagnostic. Formerly the code silently wrapped around and wrote to the wrong file, losing output data. --- src/csplit.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/csplit.c b/src/csplit.c index 531e492..9505076 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -917,19 +917,27 @@ make_filename (unsigned int num) static void create_output_file (void) { - sigset_t oldset; bool fopen_ok; int fopen_errno; output_filename = make_filename (files_created); - /* Create the output file in a critical section, to avoid races. */ - sigprocmask (SIG_BLOCK, &caught_signals, &oldset); - output_stream = fopen (output_filename, "w"); - fopen_ok = (output_stream != NULL); - fopen_errno = errno; - files_created += fopen_ok; - sigprocmask (SIG_SETMASK, &oldset, NULL); + if (files_created == UINT_MAX) + { + fopen_ok = false; + fopen_errno = EOVERFLOW; + } + else + { + /* Create the output file in a critical section, to avoid races. */ + sigset_t oldset; + sigprocmask (SIG_BLOCK, &caught_signals, &oldset); + output_stream = fopen (output_filename, "w"); + fopen_ok = (output_stream != NULL); + fopen_errno = errno; + files_created += fopen_ok; + sigprocmask (SIG_SETMASK, &oldset, NULL); + } if (! fopen_ok) { -- 1.7.2 ------------=_1303030805-1492-1--