Skip to contentSkip to conversation

fw_printenv: Fix crash due to incorrect size for malloc'ed string.

PATCH New Kristian Amlie 2 participants 2 messages Apr 4, 2018 – Apr 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fw_printenv: Fix crash due to incorrect size for malloc'ed string.

Using sizeof gives the size of the pointer only, not the string. This could easily lead to crashes when using -l argument.

---
 tools/env/fw_env_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/env/fw_env_main.c +1 -1
index d93a915..fb4afa5 100644
@@ -239,7 +239,7 @@ int main(int argc, char *argv[])
 	argv += optind;
 
 	if (env_opts.lockname) {
-		lockname = malloc(sizeof(env_opts.lockname) +
+		lockname = malloc(strlen(env_opts.lockname) +
 				sizeof(CMD_PRINTENV) + 10);
 		if (!lockname) {
 			fprintf(stderr, "Unable allocate memory");
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 fw_printenv: Fix crash due to incorrect size for malloc'ed string.

Quoted 4 lines · Kristian Amlie

Using sizeof gives the size of the pointer only, not the string. This could easily lead to crashes when using -l argument.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180411/ea5f9877/attachment.sig>