From b29925a63b9839f5fee47cd0c92cda3d0bd79a43 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Nov 2014 07:59:43 -0600 Subject: [PATCH] =?UTF-8?q?EEPROM:=20prevent=20writes=20past=20end=20of=20?= =?UTF-8?q?device.=20=20From=20S=C3=A9bastien=20Lorquet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/eeprom/spi_xx25xx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/eeprom/spi_xx25xx.c b/drivers/eeprom/spi_xx25xx.c index 91d5a3a335..cf2403952c 100644 --- a/drivers/eeprom/spi_xx25xx.c +++ b/drivers/eeprom/spi_xx25xx.c @@ -642,6 +642,13 @@ static ssize_t ee25xx_write(FAR struct file *filep, FAR const char *buffer, return ret; } + /* Forbid writes past the end of the device */ + + if (filep->f_pos >= eedev->size) + { + return -EFBIG; + } + /* Clamp len to avoid crossing the end of the memory */ if ( (len + filep->f_pos) > eedev->size)