diff mbox series

[LEDE-DEV] procd: initd: fix path allocation in early_insmod

Message ID DM5PR2201MB130720857DC16291D205D967AC050@DM5PR2201MB1307.namprd22.prod.outlook.com
State Accepted
Delegated to: John Crispin
Headers show
Series [LEDE-DEV] procd: initd: fix path allocation in early_insmod | expand

Commit Message

Nathan Hintz Dec. 29, 2017, 4:48 a.m. UTC
Noticed that /tmp was not being created on /dev/zram0.  This was on
ixp4xx (nslu2) using GCC 6.3 and musl.

The allocation should be using the length of the passed string
(module path), not the size of the pointer to the string.

Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
---
 initd/zram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Rosen Penev Dec. 29, 2017, 11:53 p.m. UTC | #1
On Thu, Dec 28, 2017 at 8:48 PM, Nathan Hintz <nlhintz@hotmail.com> wrote:
> Noticed that /tmp was not being created on /dev/zram0.  This was on
> ixp4xx (nslu2) using GCC 6.3 and musl.
>
> The allocation should be using the length of the passed string
> (module path), not the size of the pointer to the string.
>
clang-analyzer catches this as well:

/home/mangix/devstuff/procd/initd/zram.c:63:17: warning: The code
calls sizeof() on a pointer type. This can produce an unexpected
result
                path = alloca(sizeof(module) + strlen(ver.release) + 1);
                              ^     ~~~~~~~~
/usr/include/alloca.h:35:41: note: expanded from macro 'alloca'
# define alloca(size)   __builtin_alloca (size)
                                          ^~~~
1 warning generated.

> Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
> ---
>  initd/zram.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/initd/zram.c b/initd/zram.c
> index 0e78195..da1795a 100644
> --- a/initd/zram.c
> +++ b/initd/zram.c
> @@ -60,7 +60,7 @@ early_insmod(char *module)
>                 struct utsname ver;
>
>                 uname(&ver);
> -               path = alloca(sizeof(module) + strlen(ver.release) + 1);
> +               path = alloca(strlen(module) + strlen(ver.release) + 1);
>                 sprintf(path, module, ver.release);
>                 modprobe[1] = path;
>                 execvp(modprobe[0], modprobe);
> --
> 2.13.6
>
>
> _______________________________________________
> Lede-dev mailing list
> Lede-dev@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev
diff mbox series

Patch

diff --git a/initd/zram.c b/initd/zram.c
index 0e78195..da1795a 100644
--- a/initd/zram.c
+++ b/initd/zram.c
@@ -60,7 +60,7 @@  early_insmod(char *module)
 		struct utsname ver;
 
 		uname(&ver);
-		path = alloca(sizeof(module) + strlen(ver.release) + 1);
+		path = alloca(strlen(module) + strlen(ver.release) + 1);
 		sprintf(path, module, ver.release);
 		modprobe[1] = path;
 		execvp(modprobe[0], modprobe);