Message ID | 1522829397-2455-1-git-send-email-kristian.amlie@northern.tech |
---|---|
State | Accepted |
Commit | 8a0b827b1a12cf3e224a4c083de7a1e448356a16 |
Delegated to: | Tom Rini |
Headers | show |
Series | [U-Boot,1/1] fw_printenv: Fix crash due to incorrect size for malloc'ed string. | expand |
On Wed, Apr 04, 2018 at 10:09:57AM +0200, Kristian Amlie wrote: > Using sizeof gives the size of the pointer only, not the string. This > could easily lead to crashes when using -l argument. > > Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech> Applied to u-boot/master, thanks!
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c index d93a915..fb4afa5 100644 --- a/tools/env/fw_env_main.c +++ b/tools/env/fw_env_main.c @@ -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");
Using sizeof gives the size of the pointer only, not the string. This could easily lead to crashes when using -l argument. Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech> --- tools/env/fw_env_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)