--- Begin Message ---
Subject: |
[PATCH] csplit: diagnose file counter wraparound |
Date: |
Thu, 11 Nov 2010 00:28:35 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 |
(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
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#7370: [PATCH] csplit: diagnose file counter wraparound |
Date: |
Sun, 17 Apr 2011 10:59:32 +0200 |
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.
--- End Message ---