]> www.infradead.org Git - mtd-utils.git/commitdiff
mtd-utils: mtd_debug: check amount of data read.
authorMichal Suchanek <hramrach@gmail.com>
Mon, 27 Jul 2015 13:47:10 +0000 (15:47 +0200)
committerRichard Weinberger <richard@nod.at>
Thu, 25 Aug 2016 13:31:35 +0000 (15:31 +0200)
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>
misc-utils/mtd_debug.c

index d6993cec2d5475b8fb9475c8f1dd0b72594c3bc2..f3826cf05bfb11398722fb3fd3756ec54c1a79d2 100644 (file)
@@ -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()");