Skip to contentSkip to conversation

New Defects reported by Coverity Scan for Das U-Boot

PATCH In review Tom Rini 3 participants 6 messages Jan 22, 2024 – Apr 12, 2024

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

Hey all,

Here's the latest Coverity scan report.

---------- Forwarded message ---------
From: <[email protected]>
Date: Mon, Jan 22, 2024 at 6:26 PM
Subject: New Defects reported by Coverity Scan for Das U-Boot
To: <[email protected]>

Hi,

Please find the latest report on new defect(s) introduced to Das U-Boot found with Coverity Scan.

1 new defect(s) introduced to Das U-Boot found with Coverity Scan. 7 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent build analyzed by Coverity Scan.

New defect(s) Reported-by: Coverity Scan
Showing 1 of 1 defect(s)

** CID 478860: Code maintainability issues (UNUSED_VALUE) /tools/image-host.c: 359 in fit_image_read_key_iv_data()

________________________________________________________________________________________________________
*** CID 478860: Code maintainability issues (UNUSED_VALUE) /tools/image-host.c: 359 in fit_image_read_key_iv_data()
353 if (ret >= sizeof(filename)) {
354 printf("Can't format the key or IV filename
when setting up the cipher: insufficient buffer space\n");
355 ret = -1;
356 }
357 if (ret < 0) {
358 printf("Can't format the key or IV filename
when setting up the cipher: snprintf error\n");

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 478860: Code maintainability issues (UNUSED_VALUE)
Assigning value "-1" to "ret" here, but that stored value is overwritten before it can be used.

359 ret = -1;
360 }
361
362 ret = fit_image_read_data(filename, key_iv_data, expected_size);
363
364 return ret;

----- End forwarded message -----

Signature · 1 line
Tom
#1 lore raw

Hi Tom, sorry about that. Please find attached a patch.

Can you please review?

Thanks, Hugo

#2 lore raw

PATCH 1/1 image-host: Fix error value paths and emit error messages to stderr.

---
 tools/image-host.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/image-host.c +4 -4
index b2a0f2e6d1..06b05dcacb 100644
@@ -351,12 +351,12 @@ static int fit_image_read_key_iv_data(const char *keydir, const char *key_iv_nam
 	ret = snprintf(filename, sizeof(filename), "%s/%s%s",
 		       keydir, key_iv_name, ".bin");
 	if (ret >= sizeof(filename)) {
-		printf("Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
+		return -1;
 	}
 	if (ret < 0) {
-		printf("Can't format the key or IV filename when setting up the cipher: snprintf error\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: snprintf error\n");
+		return -1;
 	}
 
 	ret = fit_image_read_data(filename, key_iv_data, expected_size);
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH] image-host: Fix error value paths and emit error messages to stderr.

On 1/23/24 09:15, Hugo Cornelis wrote:

Thanks Hugo for addressing the issue. Could you, please, resend the patch with an appropriate commit message. Please, use scripts/get_maintainers.pl to determine the list of addressees.

Otherwise the patch looks good to me.

The initial assignment in fit_image_read_key_iv_data()

    int ret = -1;

is superfluous. You may want to fix that too

It helps to know which patch introduced the problem. Please, add

Fixes bc01d9ff93f3 ("image-host: refactor and protect for very long

filenames")

Best regards

Heinrich

Quoted 26 lines
---
  tools/image-host.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
tools/image-host.c +4 -4
index b2a0f2e6d1..06b05dcacb 100644
@@ -351,12 +351,12 @@ static int fit_image_read_key_iv_data(const char *keydir, const char *key_iv_nam
  	ret = snprintf(filename, sizeof(filename), "%s/%s%s",
  		       keydir, key_iv_name, ".bin");
  	if (ret >= sizeof(filename)) {
-		printf("Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
+		return -1;
  	}
  	if (ret < 0) {
-		printf("Can't format the key or IV filename when setting up the cipher: snprintf error\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: snprintf error\n");
+		return -1;
  	}
 
  	ret = fit_image_read_data(filename, key_iv_data, expected_size);
#4 lore raw

PATCH 1/1 image-host: Fix error value paths and emit error messages to stderr.

A recent refactoring in image-host.c messed up the return values of the function that reads the encryptiong keys. This patch fixes this and also makes sure that error output goes to stderr instead of to stdout.

---
 tools/image-host.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/image-host.c +5 -5
index b2a0f2e6d1..7bfc0cb6b1 100644
@@ -346,17 +346,17 @@ static int fit_image_read_key_iv_data(const char *keydir, const char *key_iv_nam
 				      unsigned char *key_iv_data, int expected_size)
 {
 	char filename[PATH_MAX];
-	int ret = -1;
+	int ret;
 
 	ret = snprintf(filename, sizeof(filename), "%s/%s%s",
 		       keydir, key_iv_name, ".bin");
 	if (ret >= sizeof(filename)) {
-		printf("Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: insufficient buffer space\n");
+		return -1;
 	}
 	if (ret < 0) {
-		printf("Can't format the key or IV filename when setting up the cipher: snprintf error\n");
-		ret = -1;
+		fprintf(stderr, "Can't format the key or IV filename when setting up the cipher: snprintf error\n");
+		return -1;
 	}
 
 	ret = fit_image_read_data(filename, key_iv_data, expected_size);
Signature · 1 line
2.34.1
author
#5 lore raw

Re: [PATCH] image-host: Fix error value paths and emit error messages to stderr.

Quoted 6 lines · Hugo Cornelis

A recent refactoring in image-host.c messed up the return values of the function that reads the encryptiong keys. This patch fixes this and also makes sure that error output goes to stderr instead of to stdout.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom