summaryrefslogtreecommitdiff
path: root/misc-utils
diff options
context:
space:
mode:
authorMichal Suchanek <hramrach@gmail.com>2015-07-27 15:47:10 +0200
committerRichard Weinberger <richard@nod.at>2016-08-25 15:31:35 +0200
commita2d188795599846bc8f085418467b794881e7209 (patch)
tree4e03dfdc42053ed79aa8d0170aac0bf54c0f6e00 /misc-utils
parent76c64d6ca9e9258b74ec13d13496eb7ca872a288 (diff)
mtd-utils: mtd_debug: check amount of data read.
The kernel refuses to read more data from a MTD device than the device size. However, mtd_debug does not check the amount of data read as returned by read(2) and assumes the requested amount is always read when there is no error. Reading 8M data from a 4M flash chip results in 8M file containing the flash data at the start. Signed-off-by: Michal Suchanek <hramrach@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/mtd_debug.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/misc-utils/mtd_debug.c b/misc-utils/mtd_debug.c
index d6993ce..f3826cf 100644
--- a/misc-utils/mtd_debug.c
+++ b/misc-utils/mtd_debug.c
@@ -141,7 +141,10 @@ retry:
perror("read()");
goto err2;
}
- err = write(outfd, buf, size);
+ if (err < size) {
+ fprintf(stderr, "%s: short read, requested %#x, read %#x\n", __func__, size, err);
+ }
+ err = write(outfd, buf, err);
if (err < 0) {
fprintf(stderr, "%s: write, size %#x, n %#x\n", __func__, size, n);
perror("write()");