Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified David Hendricks: Looks good to me, approved
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>
---
M linux_spi.c
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/linux_spi.c b/linux_spi.c
index de09e60..e3d7486 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -137,8 +137,7 @@
}

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

To view, visit change 34848. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I4f37c70e97149b87c6344e63a57d11ddde7638c4
Gerrit-Change-Number: 34848
Gerrit-PatchSet: 2
Gerrit-Owner: Jacob Garber <jgarber1@ualberta.ca>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: David Hendricks <david.hendricks@gmail.com>
Gerrit-Reviewer: Jacob Garber <jgarber1@ualberta.ca>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter@users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged