From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 88EDC4696C8 for ; Tue, 14 Apr 2020 14:38:50 +0300 (MSK) From: Alexander Turenko Date: Tue, 14 Apr 2020 14:38:15 +0300 Message-Id: <4f61389e1282fabc9f4f342b9f924f9e597f74bc.1586862436.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 06/12] popen: quote multiword command arguments List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org 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