]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
tools: check result of lseek
authorMaks Mishin <maks.mishinfz@gmail.com>
Wed, 22 Jan 2025 16:15:04 +0000 (19:15 +0300)
committerTom Rini <trini@konsulko.com>
Sun, 26 Jan 2025 17:35:46 +0000 (11:35 -0600)
Return value of function 'lseek', called at pblimage.c:211,
is not checked, but it is usually checked for this function.

This trigger was found using the Svace static analyzer.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
tools/pblimage.c

index 6c4d360e46992bc1d6fc0a29dc2291a6b7ddfd21..34650cf7b7cf006489c3fa888faa87b9adf838ef 100644 (file)
@@ -188,7 +188,7 @@ static void add_end_cmd(void)
 void pbl_load_uboot(int ifd, struct image_tool_params *params)
 {
        FILE *fp_uboot;
-       int size;
+       int size, ret;
 
        /* parse the rcw.cfg file. */
        pbl_parser(params->imagename);
@@ -208,7 +208,12 @@ void pbl_load_uboot(int ifd, struct image_tool_params *params)
                fclose(fp_uboot);
        }
        add_end_cmd();
-       lseek(ifd, 0, SEEK_SET);
+       ret = lseek(ifd, 0, SEEK_SET);
+       if (ret < 0) {
+               fprintf(stderr, "%s: lseek error %s\n",
+                       __func__, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        size = pbl_size;
        if (write(ifd, (const void *)&mem_buf, size) != size) {