Skip to contentSkip to conversation

modprobe: fix the NULL-termination of new_argv

PATCH Applied Masahiro Yamada 2 participants 4 messages Feb 10, 2022 – Apr 4, 2022

lore
Share & tools
lore
#0 lore raw

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
index 9387537..b6b2947 100644
@@ -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
#1 lore raw

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
index b6b2947..324fcfd 100644
@@ -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
#2 lore raw
In reply to Masahiro Yamada

Hi Lucas,

Ping?

Quoted 28 lines · Masahiro Yamada

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 -2
index 9387537..b6b2947 100644
@@ -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
#3 lore raw
Quoted 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_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 -2
index 9387537..b6b2947 100644
@@ -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