Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: David Sommerseth <davids@redhat.com>
Message-Id: <1477672963-5724-4-git-send-email-heiko.hund@sophos.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg12813.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -45,7 +45,6 @@ argv_init (struct argv *a) |
45 | 45 |
a->capacity = 0; |
46 | 46 |
a->argc = 0; |
47 | 47 |
a->argv = NULL; |
48 |
- a->system_str = NULL; |
|
49 | 48 |
} |
50 | 49 |
|
51 | 50 |
struct argv |
... | ... |
@@ -63,7 +62,6 @@ argv_reset (struct argv *a) |
63 | 63 |
for (i = 0; i < a->argc; ++i) |
64 | 64 |
free (a->argv[i]); |
65 | 65 |
free (a->argv); |
66 |
- free (a->system_str); |
|
67 | 66 |
argv_init (a); |
68 | 67 |
} |
69 | 68 |
|
... | ... |
@@ -98,65 +96,6 @@ argv_append (struct argv *a, char *str) /* str must have been malloced or be NUL |
98 | 98 |
a->argv[a->argc++] = str; |
99 | 99 |
} |
100 | 100 |
|
101 |
-static void |
|
102 |
-argv_system_str_append (struct argv *a, const char *str, const bool enquote) |
|
103 |
-{ |
|
104 |
- if (str) |
|
105 |
- { |
|
106 |
- char *newstr; |
|
107 |
- |
|
108 |
- /* compute length of new system_str */ |
|
109 |
- size_t l = strlen (str) + 1; /* space for new string plus trailing '\0' */ |
|
110 |
- if (a->system_str) |
|
111 |
- l += strlen (a->system_str) + 1; /* space for existing string + space (" ") separator */ |
|
112 |
- if (enquote) |
|
113 |
- l += 2; /* space for two quotes */ |
|
114 |
- |
|
115 |
- /* build new system_str */ |
|
116 |
- newstr = (char *) malloc (l); |
|
117 |
- newstr[0] = '\0'; |
|
118 |
- check_malloc_return (newstr); |
|
119 |
- if (a->system_str) |
|
120 |
- { |
|
121 |
- strcpy (newstr, a->system_str); |
|
122 |
- strcat (newstr, " "); |
|
123 |
- } |
|
124 |
- if (enquote) |
|
125 |
- strcat (newstr, "\""); |
|
126 |
- strcat (newstr, str); |
|
127 |
- if (enquote) |
|
128 |
- strcat (newstr, "\""); |
|
129 |
- free (a->system_str); |
|
130 |
- a->system_str = newstr; |
|
131 |
- } |
|
132 |
-} |
|
133 |
- |
|
134 |
-static char * |
|
135 |
-argv_extract_cmd_name (const char *path) |
|
136 |
-{ |
|
137 |
- char *ret = NULL; |
|
138 |
- if (path) |
|
139 |
- { |
|
140 |
- char *path_cp = string_alloc(path, NULL); /* POSIX basename() implementaions may modify its arguments */ |
|
141 |
- const char *bn = basename (path_cp); |
|
142 |
- if (bn) |
|
143 |
- { |
|
144 |
- char *dot = NULL; |
|
145 |
- ret = string_alloc (bn, NULL); |
|
146 |
- dot = strrchr (ret, '.'); |
|
147 |
- if (dot) |
|
148 |
- *dot = '\0'; |
|
149 |
- free(path_cp); |
|
150 |
- if (ret[0] == '\0') |
|
151 |
- { |
|
152 |
- free(ret); |
|
153 |
- ret = NULL; |
|
154 |
- } |
|
155 |
- } |
|
156 |
- } |
|
157 |
- return ret; |
|
158 |
-} |
|
159 |
- |
|
160 | 101 |
static struct argv |
161 | 102 |
argv_clone (const struct argv *a, const size_t headroom) |
162 | 103 |
{ |
... | ... |
@@ -170,7 +109,6 @@ argv_clone (const struct argv *a, const size_t headroom) |
170 | 170 |
{ |
171 | 171 |
for (i = 0; i < a->argc; ++i) |
172 | 172 |
argv_append (&r, string_alloc (a->argv[i], NULL)); |
173 |
- r.system_str = string_alloc (a->system_str, NULL); |
|
174 | 173 |
} |
175 | 174 |
return r; |
176 | 175 |
} |
... | ... |
@@ -179,17 +117,8 @@ struct argv |
179 | 179 |
argv_insert_head (const struct argv *a, const char *head) |
180 | 180 |
{ |
181 | 181 |
struct argv r; |
182 |
- char *s; |
|
183 |
- |
|
184 | 182 |
r = argv_clone (a, 1); |
185 | 183 |
r.argv[0] = string_alloc (head, NULL); |
186 |
- s = r.system_str; |
|
187 |
- r.system_str = string_alloc (head, NULL); |
|
188 |
- if (s) |
|
189 |
- { |
|
190 |
- argv_system_str_append (&r, s, false); |
|
191 |
- free (s); |
|
192 |
- } |
|
193 | 184 |
return r; |
194 | 185 |
} |
195 | 186 |
|
... | ... |
@@ -285,7 +214,6 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
285 | 285 |
if (!s) |
286 | 286 |
s = ""; |
287 | 287 |
argv_append (a, string_alloc (s, NULL)); |
288 |
- argv_system_str_append (a, s, true); |
|
289 | 288 |
} |
290 | 289 |
else if (!strcmp (term, "%sc")) |
291 | 290 |
{ |
... | ... |
@@ -304,13 +232,10 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
304 | 304 |
} |
305 | 305 |
else |
306 | 306 |
argv_append (a, string_alloc (s, NULL)); |
307 |
- |
|
308 |
- argv_system_str_append (a, s, false); |
|
309 | 307 |
} |
310 | 308 |
else |
311 | 309 |
{ |
312 | 310 |
argv_append (a, string_alloc ("", NULL)); |
313 |
- argv_system_str_append (a, "echo", false); |
|
314 | 311 |
} |
315 | 312 |
} |
316 | 313 |
else if (!strcmp (term, "%d")) |
... | ... |
@@ -318,14 +243,12 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
318 | 318 |
char numstr[64]; |
319 | 319 |
openvpn_snprintf (numstr, sizeof (numstr), "%d", va_arg (arglist, int)); |
320 | 320 |
argv_append (a, string_alloc (numstr, NULL)); |
321 |
- argv_system_str_append (a, numstr, false); |
|
322 | 321 |
} |
323 | 322 |
else if (!strcmp (term, "%u")) |
324 | 323 |
{ |
325 | 324 |
char numstr[64]; |
326 | 325 |
openvpn_snprintf (numstr, sizeof (numstr), "%u", va_arg (arglist, unsigned int)); |
327 | 326 |
argv_append (a, string_alloc (numstr, NULL)); |
328 |
- argv_system_str_append (a, numstr, false); |
|
329 | 327 |
} |
330 | 328 |
else if (!strcmp (term, "%s/%d")) |
331 | 329 |
{ |
... | ... |
@@ -346,7 +269,6 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
346 | 346 |
strcat (combined, "/"); |
347 | 347 |
strcat (combined, numstr); |
348 | 348 |
argv_append (a, combined); |
349 |
- argv_system_str_append (a, combined, false); |
|
350 | 349 |
} |
351 | 350 |
} |
352 | 351 |
else if (!strcmp (term, "%s%sc")) |
... | ... |
@@ -363,13 +285,6 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
363 | 363 |
strcpy (combined, s1); |
364 | 364 |
strcat (combined, s2); |
365 | 365 |
argv_append (a, combined); |
366 |
- |
|
367 |
- cmd_name = argv_extract_cmd_name (combined); |
|
368 |
- if (cmd_name) |
|
369 |
- { |
|
370 |
- argv_system_str_append (a, cmd_name, false); |
|
371 |
- free (cmd_name); |
|
372 |
- } |
|
373 | 366 |
} |
374 | 367 |
else |
375 | 368 |
ASSERT (0); |
... | ... |
@@ -378,7 +293,6 @@ argv_printf_arglist (struct argv *a, const char *format, va_list arglist) |
378 | 378 |
else |
379 | 379 |
{ |
380 | 380 |
argv_append (a, term); |
381 |
- argv_system_str_append (a, term, false); |
|
382 | 381 |
} |
383 | 382 |
} |
384 | 383 |
gc_free (&gc); |