summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2010-12-23 00:07:35 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2010-12-23 00:07:59 -0800
commitbc4e77927c6610d856bec90a60da931e33d3abbb (patch)
treeb2f2c77b8e60149b1aa897d2ef7b11a69e91def5 /src
parent1d0a1203777bf8478822e6dfb64cd49368a4d588 (diff)
downloadcoreutils-bc4e77927c6610d856bec90a60da931e33d3abbb.tar.xz
csplit: diagnose file counter wraparound
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/csplit.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/csplit.c b/src/csplit.c
index 07c5c8c57..9629750c9 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)
{