From: Peng Fan Date: Thu, 1 Nov 2018 06:42:01 +0000 Subject: [U-Boot] [PATCH 1/4] tools: imx8image: check lseek return value Message-ID: <20181101064937.28731-1-peng.fan@nxp.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Check lseek return value. Fix Coverity CID: 184236 184235 184232 Signed-off-by: Peng Fan --- tools/imx8image.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/imx8image.c b/tools/imx8image.c index e6b0a146b6..eb039b583d 100644 --- a/tools/imx8image.c +++ b/tools/imx8image.c @@ -333,7 +333,12 @@ static void copy_file_aligned(int ifd, const char *datafile, int offset, } size = sbuf.st_size; - lseek(ifd, offset, SEEK_SET); + if (lseek(ifd, offset, SEEK_SET) == -1) { + fprintf(stderr, "%s: lseek error %s\n", + __func__, strerror(errno)); + exit(EXIT_FAILURE); + } + if (write(ifd, ptr, size) != size) { fprintf(stderr, "Write error %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -387,7 +392,12 @@ static void copy_file (int ifd, const char *datafile, int pad, int offset) } size = sbuf.st_size; - lseek(ifd, offset, SEEK_SET); + if (lseek(ifd, offset, SEEK_SET) == -1) { + fprintf(stderr, "%s: lseek error %s\n", + __func__, strerror(errno)); + exit(EXIT_FAILURE); + } + if (write(ifd, ptr, size) != size) { fprintf(stderr, "Write error %s\n", strerror(errno)); @@ -883,7 +893,11 @@ static int build_container(soc_type_t soc, uint32_t sector_size, } while (img_sp->option != NO_IMG); /* Add padding or skip appended container */ - lseek(ofd, file_padding, SEEK_SET); + if (lseek(ofd, file_padding, SEEK_SET) == -1) { + fprintf(stderr, "%s: lseek error %s\n", + __func__, strerror(errno)); + exit(EXIT_FAILURE); + } /* Note: Image offset are not contained in the image */ tmp = flatten_container_header(&imx_header, container + 1, &size, -- 2.14.1