summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Garber <jgarber1@ualberta.ca>2019-08-12 14:14:40 -0600
committerFelix Singer <felixsinger@posteo.net>2022-09-29 17:01:37 +0000
commitee65a0357e6b836920f59a5ab50d97e2e4d4dd0f (patch)
treebb8137879fe2601a4a918ec15bc4539bce867359
parent06a344f8aa69db2ca0846df617d172e9b76c6c28 (diff)
downloadflashrom-ee65a0357e6b836920f59a5ab50d97e2e4d4dd0f.tar.gz
flashrom-ee65a0357e6b836920f59a5ab50d97e2e4d4dd0f.tar.bz2
flashrom-ee65a0357e6b836920f59a5ab50d97e2e4d4dd0f.zip
linux_spi: Use fgets() to read buffer size
Since fread() returns the number of bytes read, this currently will only check for errors if it returns 0 (i.e. the file was empty). However, it is possible for fread() to encounter an error after reading a few bytes, which this doesn't catch. Fix this by using fgets() instead, which will return NULL if EOF or an error is encountered, and is simpler anyway. Change-Id: I4f37c70e97149b87c6344e63a57d11ddde7638c4 Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 1403824 Reviewed-on: https://review.coreboot.org/c/flashrom/+/34848 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67848 Reviewed-by: Felix Singer <felixsinger@posteo.net>
-rw-r--r--linux_spi.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/linux_spi.c b/linux_spi.c
index 711ab4ac9..bcac8cb10 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -138,8 +138,7 @@ int linux_spi_init(void)
}
char buf[10];
- memset(buf, 0, sizeof(buf));
- if (!fread(buf, 1, sizeof(buf) - 1, fp)) {
+ if (!fgets(buf, sizeof(buf), fp)) {
if (feof(fp))
msg_pwarn("Cannot read %s: file is empty.\n", BUF_SIZE_FROM_SYSFS);
else