mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
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.
This commit is contained in:
1 parent
1d0a120377
commit
bc4e77927c
1 file changed
+16
-8
+16
-8
@@ -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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user