summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2019-10-08 22:24:07 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-12 06:33:05 -0400
commitf1ce3535d20007dc78aeed096f32fc9dfacf11b3 (patch)
tree1edd6e8092ff6bfcc5c6d43cb7090289f9fbe1e8 /rts
parentc2290596f10ce732be85503d3ef0f0b50b7e925a (diff)
downloadhaskell-f1ce3535d20007dc78aeed096f32fc9dfacf11b3.tar.gz
Escape stats file command (#13676)
Diffstat (limited to 'rts')
-rw-r--r--rts/RtsFlags.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index d4301c414f..d36e9ffc66 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1777,16 +1777,30 @@ openStatsFile (char *filename, // filename, or NULL
* and the arguments it was invoked with.
-------------------------------------------------------------------------- */
+// stats_fprintf augmented with Bash-compatible escaping. See #13676
+static void stats_fprintf_escape (FILE *f, char*s)
+{
+ stats_fprintf(f, "'");
+ while (*s != '\0') {
+ switch (*s) {
+ case '\'': stats_fprintf(f, "'\\''"); break;
+ default: stats_fprintf(f, "%c", *s); break;
+ }
+ ++s;
+ }
+ stats_fprintf(f, "' ");
+}
+
static void initStatsFile (FILE *f)
{
/* Write prog_argv and rts_argv into start of stats file */
int count;
for (count = 0; count < prog_argc; count++) {
- stats_fprintf(f, "%s ", prog_argv[count]);
+ stats_fprintf_escape(f, prog_argv[count]);
}
stats_fprintf(f, "+RTS ");
for (count = 0; count < rts_argc; count++)
- stats_fprintf(f, "%s ", rts_argv[count]);
+ stats_fprintf_escape(f, rts_argv[count]);
stats_fprintf(f, "\n");
}