modprobe: fix the NULL-termination of new_argv
PATCH 1/2 modprobe: fix the NULL-termination of new_argv
The number of new arguments is (i + argc - 1) as it is set to *p_argc one line below.
The correct location of NULL termination is new_argv[i + argc - 1].
---
tools/modprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/modprobe.c +1 -1
@@ -743,7 +743,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv) }memcpy (new_argv + i, orig_argv +1 ,sizeof (char *) * (argc -1 )); - new_argv[i + argc] =NULL ; + new_argv[i + argc -1 ] =NULL ; *p_argc = i + argc -1 ;return new_argv;
Signature · 1 line
2.32.0
PATCH 2/2 modprobe: remove unneeded variable str_start
The variable 'str_start' is not useful here.
Replace it with 'str'.
---
tools/modprobe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/modprobe.c +3 -3
@@ -683,7 +683,7 @@ static int options_from_array(char **args, int nargs, char **output)static char **prepend_options_from_env (int *p_argc,char **orig_argv) {const char *p, *env =getenv ("MODPROBE_OPTIONS" ); -char **new_argv, *str_start, *str_end, *str, *s, *quote; +char **new_argv, *str_end, *str, *s, *quote;int i, argc = *p_argc;size_t envlen, space_count =0 ;
@@ -701,10 +701,10 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)return NULL ; new_argv[0 ] = orig_argv[0 ]; - str_start = str = (char *) (new_argv + argc + space_count +3 ); + str = (char *) (new_argv + argc + space_count +3 );memcpy (str, env, envlen +1 ); - str_end = str_start + envlen; + str_end = str + envlen; quote =NULL ;for (i =1 , s = str; *s !='\0' ; s++) {
Signature · 1 line
2.32.0
Hi Lucas,
Ping?
Quoted 28 lines · Masahiro Yamada
The number of new arguments is (i + argc - 1) as it is set to
*p_argcone line below.The correct location of NULL termination is new_argv[i + argc - 1].
Signed-off-by Masahiro Yamada <[email protected]>---
tools/modprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/modprobe.c +1
-2@@ -743,7 +743,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv) }memcpy (new_argv + i, orig_argv +1 ,sizeof (char *) * (argc -1 )); - new_argv[i + argc] =NULL ; + new_argv[i + argc -1 ] =NULL ; *p_argc = i + argc -1 ;return new_argv; --2.32.0
Signature · 2 lines
Best Regards Masahiro Yamada
Lucas De Marchi
AppliedQuoted 3 lines · Masahiro Yamada
Hi Lucas,
Ping?
sorry for the delay. These 2 patches look good to me.
Applied. Thanks
Lucas De Marchi
Quoted 36 lines · Masahiro Yamada
Quoted 28 lines
The number of new arguments is (i + argc - 1) as it is set to
*p_argcone line below.The correct location of NULL termination is new_argv[i + argc - 1].
Signed-off-by Masahiro Yamada <[email protected]>---
tools/modprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/modprobe.c +1
-2@@ -743,7 +743,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv) }memcpy (new_argv + i, orig_argv +1 ,sizeof (char *) * (argc -1 )); - new_argv[i + argc] =NULL ; + new_argv[i + argc -1 ] =NULL ; *p_argc = i + argc -1 ;return new_argv; --2.32.0
Signature · 2 lines
Best Regards Masahiro Yamada