summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-10-07 13:12:36 +0100
committerPádraig Brady <P@draigBrady.com>2010-10-07 20:08:16 +0100
commit758916b49e69836fcbd1e861e19edfced44e28ea (patch)
treef1f3f1b4117e9efb4ea1f27bb1e9a0b5e4453579
parent6483f0e1bd4ae5b5b300512c96cc3028d643a58c (diff)
downloadcoreutils-758916b49e69836fcbd1e861e19edfced44e28ea.tar.xz
split: fix reporting of read errors
The bug was introduced with commit 23f6d41f, 19-02-2003. * src/split.c (bytes_split, lines_split, line_bytes_split): Correctly check the return from full_read(). * tests/misc/split-fail: Ensure split fails when it can't read its input. * NEWS: Mention the fix.
-rw-r--r--NEWS3
-rw-r--r--src/split.c11
-rwxr-xr-xtests/misc/split-fail6
3 files changed, 14 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 22f257ba6..7ee18cdd1 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ GNU coreutils NEWS -*- outline -*-
found to be part of a directory cycle. Before, du would issue a
"NOTIFY YOUR SYSTEM MANAGER" diagnostic and fail.
+ split now diagnoses read errors rather than silently exiting.
+ [bug introduced in coreutils-4.5.8]
+
tac would perform a double-free when given an input line longer than 16KiB.
[bug introduced in coreutils-8.3]
diff --git a/src/split.c b/src/split.c
index 5be720795..61ae265d8 100644
--- a/src/split.c
+++ b/src/split.c
@@ -33,7 +33,6 @@
#include "full-read.h"
#include "full-write.h"
#include "quote.h"
-#include "safe-read.h"
#include "xfreopen.h"
#include "xstrtol.h"
@@ -229,7 +228,7 @@ bytes_split (uintmax_t n_bytes, char *buf, size_t bufsize)
do
{
n_read = full_read (STDIN_FILENO, buf, bufsize);
- if (n_read == SAFE_READ_ERROR)
+ if (n_read < bufsize && errno)
error (EXIT_FAILURE, errno, "%s", infile);
bp_out = buf;
to_read = n_read;
@@ -273,7 +272,7 @@ lines_split (uintmax_t n_lines, char *buf, size_t bufsize)
do
{
n_read = full_read (STDIN_FILENO, buf, bufsize);
- if (n_read == SAFE_READ_ERROR)
+ if (n_read < bufsize && errno)
error (EXIT_FAILURE, errno, "%s", infile);
bp = bp_out = buf;
eob = bp + n_read;
@@ -314,7 +313,6 @@ lines_split (uintmax_t n_lines, char *buf, size_t bufsize)
static void
line_bytes_split (size_t n_bytes)
{
- size_t n_read;
char *bp;
bool eof = false;
size_t n_buffered = 0;
@@ -324,8 +322,9 @@ line_bytes_split (size_t n_bytes)
{
/* Fill up the full buffer size from the input file. */
- n_read = full_read (STDIN_FILENO, buf + n_buffered, n_bytes - n_buffered);
- if (n_read == SAFE_READ_ERROR)
+ size_t to_read = n_bytes - n_buffered;
+ size_t n_read = full_read (STDIN_FILENO, buf + n_buffered, to_read);
+ if (n_read < to_read && errno)
error (EXIT_FAILURE, errno, "%s", infile);
n_buffered += n_read;
diff --git a/tests/misc/split-fail b/tests/misc/split-fail
index e36c86dc9..68c9d7334 100755
--- a/tests/misc/split-fail
+++ b/tests/misc/split-fail
@@ -64,5 +64,11 @@ split: line count option -99*... is too large
EOF
compare out exp || fail=1
+# Make sure split fails when it can't read input
+# (the current directory in this case)
+if ! cat . >/dev/null; then
+ # can't read() directories
+ split . && fail=1
+fi
Exit $fail