Skip to contentSkip to conversation

hwsim: check if radio name was already set

PATCH Applied James Prestwood 2 participants 6 messages Feb 18, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/3 hwsim: check if radio name was already set

This was caught by static analysis and shouldn't ever happen.

---
 tools/hwsim.c | 3 +++
 1 file changed, 3 insertions(+)
tools/hwsim.c +3 -0
index 3ff3faab..8c076f51 100644
@@ -639,6 +639,9 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)
 			break;
 
 		case HWSIM_ATTR_RADIO_NAME:
+			if (name)
+				return;
+
 			name = l_strndup(data, len);
 			break;
 		}
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/3 main: remove unneeded stat call

Static analysis flagged that 'path' was never being checked (which should not ever be NULL) but during that review I noticed stat() was being called, then fstat afterwards.

---
 src/main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
src/main.c +1 -4
index 7a378b64..d790f61f 100644
@@ -428,11 +428,8 @@ static bool setup_system_key(void)
 	}
 
 	path = l_strdup_printf("%s/%s", cred_dir, key_id);
-
-	if (stat(path, &st) < 0) {
-		l_warn("SystemdEncrypt: Could not stat %s", path);
+	if (!path)
 		return false;
-	}
 
 	fd = open(path, O_RDONLY, 0);
 	if (fd < 0) {
Signature · 1 line
2.34.1
Applied
#2 lore raw

Re: [PATCH 2/3] main: remove unneeded stat call

Hi James,

Quoted 12 lines · James Prestwood

Static analysis flagged that 'path' was never being checked (which should not ever be NULL) but during that review I noticed stat() was being called, then fstat afterwards.

---
  src/main.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
src/main.c +0 -0
index 7a378b64..d790f61f 100644

src/main.c static bool setup_system_key(void) · line 432

Quoted 8 lines
src/main.c +1 -3
@@ -428,11 +428,8 @@ static bool setup_system_key(void)
  	}
 
  	path = l_strdup_printf("%s/%s", cred_dir, key_id);
-
-	if (stat(path, &st) < 0) {
-		l_warn("SystemdEncrypt: Could not stat %s", path);
+	if (!path)
  		return false;

l_strdup_printf doesn't fail, so I removed this if as well.

src/main.c static bool setup_system_key(void) · line 435

Quoted 5 lines
src/main.c +0 -1
-	}
 
  	fd = open(path, O_RDONLY, 0);
  	if (fd < 0) {

Applied, thanks.

Regards,
-Denis

author
#3 lore raw

PATCH 3/3 dpp: check return of aes_siv_encrypt

In reply to James Prestwood

This was caught by static analysis. As is common this should never happen in the real world since the only way this can fail (apart from extreme circumstances like OOM) is if the key size is incorrect, which it will never be.

---
 src/dpp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/dpp.c +5 -2
index f664e490..54662e8f 100644
@@ -1070,8 +1070,11 @@ static void send_authenticate_response(struct dpp_sm *dpp)
 	 * do not use AAD; in other words, the number of AAD components is set
 	 * to zero.""
 	 */
-	aes_siv_encrypt(dpp->ke, dpp->key_len, wrapped2_plaintext,
-					dpp->key_len + 4, NULL, 0, wrapped2);
+	if (!aes_siv_encrypt(dpp->ke, dpp->key_len, wrapped2_plaintext,
+					dpp->key_len + 4, NULL, 0, wrapped2)) {
+		l_error("Failed to encrypt wrapped data");
+		return;
+	}
 
 	wrapped2_len += 16;
 
Signature · 1 line
2.34.1
Applied
#4 lore raw

Re: [PATCH 3/3] dpp: check return of aes_siv_encrypt

Hi James,

Quoted 8 lines · James Prestwood

This was caught by static analysis. As is common this should never happen in the real world since the only way this can fail (apart from extreme circumstances like OOM) is if the key size is incorrect, which it will never be.

---
  src/dpp.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.

Regards,
-Denis

Applied
#5 lore raw
In reply to James Prestwood
Quoted 10 lines · James Prestwood

This was caught by static analysis and shouldn't ever happen.

---
  tools/hwsim.c | 3 +++
  1 file changed, 3 insertions(+)
tools/hwsim.c +0 -0
index 3ff3faab..8c076f51 100644

tools/hwsim.c static void get_radio_callback(struct l_genl_msg *msg, void *user_data) · line 644

Quoted 6 lines
tools/hwsim.c +3 -0
@@ -639,6 +639,9 @@ static void get_radio_callback(struct l_genl_msg *msg, void *user_data)
  			break;
 
  		case HWSIM_ATTR_RADIO_NAME:
+			if (name)
+				return;
+

I changed this to break instead of return.

tools/hwsim.c static void get_radio_callback(struct l_genl_msg *msg, void *user_data) · line 647

Quoted 4 lines
tools/hwsim.c +0 -0
  			name = l_strndup(data, len);
  			break;
  		}

Applied, thanks.

Regards,
-Denis