Skip to contentSkip to conversation

tools: check result of lseek

PATCH In review Maks Mishin 2 participants 3 messages Jan 22, 2025 – Jan 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: check result of lseek

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.

---
 tools/pblimage.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/pblimage.c +7 -2
index 6c4d360e46..34650cf7b7 100644
@@ -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) {
Signature · 1 line
2.43.0
#2 lore raw
In reply to Maks Mishin
Quoted 6 lines · Maks Mishin

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom