summaryrefslogtreecommitdiff
path: root/tools/zynqmpimage.c
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2017-12-05 15:42:25 +0100
committerMichal Simek <michal.simek@xilinx.com>2017-12-18 09:32:06 +0100
commit6d0cbbd5967b42100253e4d8ceff610d1edf3897 (patch)
tree56612066e0221e6ddd66347b83bdb3275b5ff8bc /tools/zynqmpimage.c
parent3a55cb38c5335901be9550d77f7672ae37f0fa99 (diff)
downloadu-boot-6d0cbbd5967b42100253e4d8ceff610d1edf3897.tar.gz
tools: zynqmpimage: Check return values from file functions
Check all return values from file functions. In case of negative return exit immediately. Also change fsize return value which can't be negative. Reported-by: Coverity (CID: 23276, 23304, 169357) Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Diffstat (limited to 'tools/zynqmpimage.c')
-rw-r--r--tools/zynqmpimage.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
index 9667b11b2f..f48ac6dbe5 100644
--- a/tools/zynqmpimage.c
+++ b/tools/zynqmpimage.c
@@ -245,16 +245,38 @@ static int zynqmpimage_check_image_types(uint8_t type)
return EXIT_FAILURE;
}
-static int fsize(FILE *fp)
+static uint32_t fsize(FILE *fp)
{
- int size;
- int origin = ftell(fp);
+ int size, ret, origin;
+
+ origin = ftell(fp);
+ if (origin < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(2);
+ }
+
+ ret = fseek(fp, 0L, SEEK_END);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_END\n");
+ fclose(fp);
+ exit(3);
+ }
- fseek(fp, 0L, SEEK_END);
size = ftell(fp);
+ if (size < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(4);
+ }
/* going back */
- fseek(fp, origin, SEEK_SET);
+ ret = fseek(fp, origin, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_SET to %d\n", origin);
+ fclose(fp);
+ exit(3);
+ }
return size;
}