>From ac6837d1d76e01126b98fc97df6226fc26ea365f Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?=
Date: Thu, 7 Oct 2010 13:12:36 +0100 Subject: [PATCH] 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(). * NEWS: Mention the fix. --- NEWS | 3 +++ src/split.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 719ac9c..7136c2a 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 5be7207..90e2c76 100644 --- a/src/split.c +++ b/src/split.c @@ -229,7 +229,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 +273,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; @@ -325,7 +325,7 @@ 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) + if (n_read < (n_bytes - n_buffered) && errno) error (EXIT_FAILURE, errno, "%s", infile); n_buffered += n_read; -- 1.6.2.5