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>
This commit is contained in:
parent
3a55cb38c5
commit
6d0cbbd596
@ -245,16 +245,38 @@ static int zynqmpimage_check_image_types(uint8_t type)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsize(FILE *fp)
|
static uint32_t fsize(FILE *fp)
|
||||||
{
|
{
|
||||||
int size;
|
int size, ret, origin;
|
||||||
int origin = ftell(fp);
|
|
||||||
|
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);
|
size = ftell(fp);
|
||||||
|
if (size < 0) {
|
||||||
|
fprintf(stderr, "Incorrect file size\n");
|
||||||
|
fclose(fp);
|
||||||
|
exit(4);
|
||||||
|
}
|
||||||
|
|
||||||
/* going back */
|
/* 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;
|
return size;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user