Check lseek return value. Fix Coverity CID: 184236 184235 184232
Signed-off-by: Peng Fan <peng....@nxp.com> --- 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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot