Busybox dd expects that read() calls (as provided by safe_read) will
always return the requested amount of data unless at EOF. This isn't
true for safe_read(), but it is true for full_read() (which loops
over safe_read until enough data has been retrieved).

This patch replaces dd's safe_read() calls with full_read() to make
sure that the underlying assumptions about read-length always hold
true.

Without this patch, users on some platforms can get corrupted reads
or incomplete skips.

Signed-off-by: Nicholas Clark <nicholas.clark at gmail.com>
---
 coreutils/dd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/coreutils/dd.c b/coreutils/dd.c
index d302f35d3..6fc062d8d 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -450,7 +450,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
  size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
  if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
  do {
- ssize_t n = safe_read(ifd, ibuf, blocksz);
+ ssize_t n = full_read(ifd, ibuf, blocksz);
  if (n < 0)
  goto die_infile;
  if (n == 0)
@@ -466,7 +466,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
  while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
  ssize_t n;

- n = safe_read(ifd, ibuf, ibs);
+ n = full_read(ifd, ibuf, ibs);
  if (n == 0)
  break;
  if (n < 0) {
-- 
2.11.0
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to