]> www.infradead.org Git - mtd-utils.git/commitdiff
libmtd: mtd_read: Take the buffer offset into account when reading
authorMarcus Prebble <marcus.prebble@axis.com>
Tue, 6 Oct 2015 12:13:23 +0000 (14:13 +0200)
committerBrian Norris <computersforpeace@gmail.com>
Tue, 17 Nov 2015 20:31:37 +0000 (12:31 -0800)
Assuming the read() call does not return zero and the result is less
than len, the current implementation will overwrite the data already
read in buf which doesn't seem correct.

With this patch, subsequent calls to read() within the loop will now no
longer overwrite the existing contents of buf.

Signed-off-by: Marcus Prebble <marcus.prebble@axis.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
lib/libmtd.c

index 60b4782710c81aa3d38519c5ebc599b94a2689de..bf6d71fabf9717e4164ce9411b9a80603de17e13 100644 (file)
@@ -1072,10 +1072,10 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
                                  mtd->mtd_num, seek);
 
        while (rd < len) {
-               ret = read(fd, buf, len);
+               ret = read(fd, buf + rd, len - rd);
                if (ret < 0)
                        return sys_errmsg("cannot read %d bytes from mtd%d (eraseblock %d, offset %d)",
-                                         len, mtd->mtd_num, eb, offs);
+                                         len - rd, mtd->mtd_num, eb, offs + rd);
                rd += ret;
        }