[PATCH 4/5] devfs: don't erase past the end of the partition

Johannes Stezenbach js at sig21.net
Wed Jun 6 12:04:59 EDT 2012


"erase /dev/myflash0.mypart 0xf0000+0xf0000" could erase past
the end of the partition.

Signed-off-by: Johannes Stezenbach <js at sig21.net>
---
 fs/devfs.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/devfs.c b/fs/devfs.c
index e3a21ae..ae48451 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -73,6 +73,9 @@ static int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned lo
 	if (!cdev->ops->erase)
 		return -ENOSYS;
 
+	if (count + offset > cdev->size)
+		count = cdev->size - offset;
+
 	return cdev->ops->erase(cdev, count, offset + cdev->offset);
 }
 
-- 
1.7.10




More information about the barebox mailing list