From c5d179123df5e7d8b72e613935b9e1bd278886f9 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Sat, 9 Aug 2014 17:02:00 +0200 Subject: nvramtool: check for successful seek Otherwise the following write might end up anywhere. Change-Id: Ie42d984824e9308bd58b8bb905b6ea823543adf0 Found-by: Coverity Scan Signed-off-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/6560 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan Reviewed-by: Stefan Reinauer --- util/nvramtool/cli/nvramtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/nvramtool/cli/nvramtool.c b/util/nvramtool/cli/nvramtool.c index d5acc5838e..bdfaaff26d 100644 --- a/util/nvramtool/cli/nvramtool.c +++ b/util/nvramtool/cli/nvramtool.c @@ -163,8 +163,8 @@ int main(int argc, char *argv[]) } if (fd_stat.st_size < CMOS_SIZE) { - lseek(fd, CMOS_SIZE - 1, SEEK_SET); - if (write(fd, "\0", 1) != 1) { + if ((lseek(fd, CMOS_SIZE - 1, SEEK_SET) == -1) || + (write(fd, "\0", 1) != 1)) { fprintf(stderr, "Unable to extended '%s' to its full size.\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param); exit(1); -- cgit v1.2.3