]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Split EDITOR in space-separated parts so that it may arguments to the editor. 16120/head
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Sep 2025 06:11:25 +0000 (08:11 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Sep 2025 07:24:53 +0000 (09:24 +0200)
Fixes: #16117
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/pdnsutil.cc

index 7060cc1855f6d75f99bc1de68d810754b010d6b4..cd3f47aa868c7a3da08e5cb75d8d292bb5c36cf5 100644 (file)
@@ -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<const char *, 4> args{};
-      size_t pos{0};
+      std::vector<std::string> 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<char **>(args.data())) != 0) { // NOLINT(cppcoreguidelines-pro-type-const-cast)
+      std::vector<const char*> 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<char * const*>(argv.data())) != 0) { // NOLINT(cppcoreguidelines-pro-type-const-cast)
         ::exit(errno); // NOLINT(concurrency-mt-unsafe)
       }
       // std::unreachable();