From 75d4a2ca5fffd2c967074938ae06fa15bfe8053c Mon Sep 17 00:00:00 2001 From: Ye Li Date: Tue, 13 Nov 2018 00:23:14 -0800 Subject: [PATCH] MLK-20239-5 imx8qm/qxp: check lseek return value Fix coverity issue CID 1900601, CID 2872685, CID 3327494: Unchecked return value from library (CHECKED_RETURN) check_return: Calling lseek(ifd, offset, 0) without checking return value. This library function may fail and return an error code Signed-off-by: Ye Li --- src/imx8qxb0.c | 17 +++++++++++++++-- src/mkimage_imx8.c | 10 ++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/imx8qxb0.c b/src/imx8qxb0.c index 1180a98..46184c3 100644 --- a/src/imx8qxb0.c +++ b/src/imx8qxb0.c @@ -137,6 +137,7 @@ static void copy_file_aligned (int ifd, const char *datafile, int offset, int al unsigned char *ptr; uint8_t zeros[0x4000]; int size; + int ret; if (align > 0x4000) { fprintf (stderr, "Wrong alignment requested %d\n", @@ -169,7 +170,13 @@ static void copy_file_aligned (int ifd, const char *datafile, int offset, int al } size = sbuf.st_size; - lseek(ifd, offset, SEEK_SET); + ret = lseek(ifd, offset, SEEK_SET); + if (ret < 0) { + 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)); @@ -545,6 +552,7 @@ int build_container_qx_qm_b0(soc_type_t soc, uint32_t sector_size, uint32_t ivt_ char *tmp_filename = NULL; uint32_t size = 0; uint32_t file_padding = 0; + int ret; int container = -1; int cont_img_count = 0; /* indexes to arrange the container */ @@ -679,7 +687,12 @@ int build_container_qx_qm_b0(soc_type_t soc, uint32_t sector_size, uint32_t ivt_ } while (img_sp->option != NO_IMG); /* Add padding or skip appended container */ - lseek(ofd, file_padding, SEEK_SET); + ret = lseek(ofd, file_padding, SEEK_SET); + if (ret < 0) { + fprintf(stderr, "%s: lseek error %s\n", + __func__, strerror(errno)); + exit(EXIT_FAILURE); + } /* Note: Image offset are not contained in the image */ uint8_t *tmp = flatten_container_header(&imx_header, container + 1, &size, file_padding); diff --git a/src/mkimage_imx8.c b/src/mkimage_imx8.c index 151733a..7d1aee3 100644 --- a/src/mkimage_imx8.c +++ b/src/mkimage_imx8.c @@ -109,7 +109,7 @@ copy_file (int ifd, const char *datafile, int pad, int offset) int tail; int zero = 0; uint8_t zeros[4096]; - int size; + int size, ret; memset(zeros, 0, sizeof(zeros)); @@ -136,7 +136,13 @@ copy_file (int ifd, const char *datafile, int pad, int offset) } size = sbuf.st_size; - lseek(ifd, offset, SEEK_SET); + ret = lseek(ifd, offset, SEEK_SET); + if (ret < 0) { + 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)); -- 2.26.2