[Tarantool-patches] [PATCH 06/12] popen: quote multiword command arguments
Alexander Turenko
alexander.turenko at tarantool.org
Tue Apr 14 14:38:15 MSK 2020
Of course it is still not fair shell-style quoting: at least we should
also escape quotes inside arguments. But it gives correct output for
most of typical commands and has straightforward implementation.
Part of #4031
---
src/lib/core/popen.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c
index 3ba1e2a48..089c84830 100644
--- a/src/lib/core/popen.c
+++ b/src/lib/core/popen.c
@@ -154,7 +154,7 @@ handle_new(struct popen_opts *opts)
for (i = 0; i < opts->nr_argv; i++) {
if (opts->argv[i] == NULL)
continue;
- size += strlen(opts->argv[i]) + 1;
+ size += strlen(opts->argv[i]) + 3;
}
handle = malloc(sizeof(*handle) + size);
@@ -168,8 +168,13 @@ handle_new(struct popen_opts *opts)
for (i = 0; i < opts->nr_argv-1; i++) {
if (opts->argv[i] == NULL)
continue;
+ bool is_multiword = strchr(opts->argv[i], ' ') != NULL;
+ if (is_multiword)
+ *pos++ = '\'';
strcpy(pos, opts->argv[i]);
pos += strlen(opts->argv[i]);
+ if (is_multiword)
+ *pos++ = '\'';
*pos++ = ' ';
}
pos[-1] = '\0';
--
2.25.0
More information about the Tarantool-patches
mailing list