Patrick Georgi (pgeorgi@google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15962
-gerrit
commit 311cf28bc9cda89aaf6e33956caae676006e74e9 Author: Patrick Georgi pgeorgi@chromium.org Date: Fri Jul 29 18:28:42 2016 +0200
intelvbttool: cope with errors in open()
Change-Id: I9fee87b7331ee05d4e984cb024f124abb2c97a69 Signed-off-by: Patrick Georgi pgeorgi@chromium.org Found-by: Coverity Scan #1347357 --- util/intelvbttool/intelvbttool.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/util/intelvbttool/intelvbttool.c b/util/intelvbttool/intelvbttool.c index 31fc24a..f0216dd 100644 --- a/util/intelvbttool/intelvbttool.c +++ b/util/intelvbttool/intelvbttool.c @@ -515,13 +515,20 @@ int main(int argc, char **argv) { const void *ptr; int fd; + off_t offset; if (argc == 2) { fd = open(argv[1], O_RDONLY); - ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0); + offset = 0; } else { fd = open("/dev/mem", O_RDONLY); - ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0xc0000); + offset = 0xc0000; } + if (fd < 0) { + fprintf(stderr, "open failed: %s\n", strerror(errno)); + return 1; + } + + ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, offset); if (ptr == MAP_FAILED) { fprintf(stderr, "mmap failed: %s\n", strerror(errno)); return 1;