[PATCH] D90759: Escape command line arguments in backtraces

Luke Drummond via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 17 04:16:47 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG537cbd90c43d: Escape command line arguments in backtraces (authored by ldrumm).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90759/new/

https://reviews.llvm.org/D90759

Files:
  llvm/lib/Support/PrettyStackTrace.cpp


Index: llvm/lib/Support/PrettyStackTrace.cpp
===================================================================
--- llvm/lib/Support/PrettyStackTrace.cpp
+++ llvm/lib/Support/PrettyStackTrace.cpp
@@ -25,6 +25,7 @@
 #include <cassert>
 #include <cstdarg>
 #include <cstdio>
+#include <cstring>
 #include <tuple>
 
 #ifdef HAVE_CRASHREPORTERCLIENT_H
@@ -253,8 +254,16 @@
 void PrettyStackTraceProgram::print(raw_ostream &OS) const {
   OS << "Program arguments: ";
   // Print the argument list.
-  for (unsigned i = 0, e = ArgC; i != e; ++i)
-    OS << ArgV[i] << ' ';
+  for (int I = 0; I < ArgC; ++I) {
+    const bool HaveSpace = ::strchr(ArgV[I], ' ');
+    if (I)
+      OS << ' ';
+    if (HaveSpace)
+      OS << '"';
+    OS.write_escaped(ArgV[I]);
+    if (HaveSpace)
+      OS << '"';
+  }
   OS << '\n';
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90759.305732.patch
Type: text/x-patch
Size: 820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201117/010b47a6/attachment.bin>


More information about the llvm-commits mailing list