From: Miod Vallat Date: Mon, 15 Sep 2025 06:11:25 +0000 (+0200) Subject: Split EDITOR in space-separated parts so that it may arguments to the editor. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F16120%2Fhead;p=thirdparty%2Fpdns.git Split EDITOR in space-separated parts so that it may arguments to the editor. Fixes: #16117 Signed-off-by: Miod Vallat --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 7060cc185..cd3f47aa8 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1863,18 +1863,22 @@ static bool spawnEditor(const std::string& editor, std::string_view tmpfile, int switch (pid_t child = fork()) { case 0: { - std::array args{}; - size_t pos{0}; + std::vector parts; std::string gotolinestr; - args.at(pos++) = editor.c_str(); + stringtok(parts, editor, " \t"); if (gotoline > 0) { // TODO: if editor is 'ed', skip this; if 'ex' or 'vi', use '-c number' gotolinestr = "+" + std::to_string(gotoline); - args.at(pos++) = gotolinestr.c_str(); + parts.emplace_back(gotolinestr); } - args.at(pos++) = tmpfile.data(); - args.at(pos++) = nullptr; - if (::execvp(args.at(0), const_cast(args.data())) != 0) { // NOLINT(cppcoreguidelines-pro-type-const-cast) + std::vector argv; + argv.reserve(parts.size() + 2); + for (const auto& part : parts) { + argv.emplace_back(part.c_str()); + } + argv.emplace_back(tmpfile.data()); + argv.emplace_back(nullptr); + if (::execvp(argv.at(0), const_cast(argv.data())) != 0) { // NOLINT(cppcoreguidelines-pro-type-const-cast) ::exit(errno); // NOLINT(concurrency-mt-unsafe) } // std::unreachable();