fw_printenv: Fix crash due to incorrect size for malloc'ed string.
authorKristian Amlie <kristian.amlie@northern.tech>
Wed, 4 Apr 2018 08:09:57 +0000 (10:09 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 10 Apr 2018 19:19:15 +0000 (15:19 -0400)
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

index d93a915fd142827e2259cd78b260565e4c4e76e6..fb4afa5ee91c427a4604f4d602a299c11febbdae 100644 (file)
@@ -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");