Skip to contentSkip to conversation

fastboot: Fix off by 1 error

PATCH In review Andrew Goodbody 3 participants 3 messages Jul 17, 2025 – Jul 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fastboot: Fix off by 1 error

strlen only reports length of string not including terminating 0 byte but this has to be included in length of receiving buffer on copy so adjust length check to be correct.

This issue found by Smatch.

---
 drivers/fastboot/fb_command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fastboot/fb_command.c +1 -1
index 2cdbac50ac4..df6e2a81cd5 100644
@@ -405,7 +405,7 @@ static void __maybe_unused run_acmd(char *cmd_parameter, char *response)
 		return;
 	}
 
-	if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) {
+	if (strlen(cmd_parameter) >= sizeof(g_a_cmd_buff)) {
 		pr_err("too long command\n");
 		fastboot_fail("too long command", response);
 		return;

---
base-commit: 3b4604a40b9fd61b87e9d059fc56f04d36f1a380
change-id: 20250717-fb_command-275ca03b1f03

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw

Hi Andrew,

Thank you for the patch.

Quoted 5 lines · Andrew Goodbody

strlen only reports length of string not including terminating 0 byte but this has to be included in length of receiving buffer on copy so adjust length check to be correct.

This issue found by Smatch.

This issue was*

Quoted 2 lines

Good catch!

Quoted 25 lines
---
 drivers/fastboot/fb_command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fastboot/fb_command.c +1 -2
index 2cdbac50ac4..df6e2a81cd5 100644
@@ -405,7 +405,7 @@ static void __maybe_unused run_acmd(char *cmd_parameter, char *response)
 		return;
 	}
 
-	if (strlen(cmd_parameter) > sizeof(g_a_cmd_buff)) {
+	if (strlen(cmd_parameter) >= sizeof(g_a_cmd_buff)) {
 		pr_err("too long command\n");
 		fastboot_fail("too long command", response);
 		return;
 
---

base-commit: 3b4604a40b9fd61b87e9d059fc56f04d36f1a380
change-id: 20250717-fb_command-275ca03b1f03

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#2 lore raw
In reply to Andrew Goodbody
Quoted 8 lines · Andrew Goodbody

strlen only reports length of string not including terminating 0 byte but this has to be included in length of receiving buffer on copy so adjust length check to be correct.

This issue found by Smatch.

[...]

Applied to u-boot/master, thanks!

[1/1] fastboot: Fix off by 1 error

      commit: 23d2c182d4be9f993a4e4d8f4fc6293e4d5a9ff8
Signature · 1 line
Tom