summaryrefslogtreecommitdiffstats
path: root/compress.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2016-11-13 20:02:36 -0800
committerKevin McCarthy <kevin@8t8.us>2016-11-13 20:02:36 -0800
commitaa8f2cdf2f95bde8087887b2e439677056ce0efd (patch)
tree09969742036281e301bd59a07dc37dbf338f07ea /compress.c
parentdf33e1f12ebeca196a7c88989df6205a78c3a624 (diff)
Compress: escape single quotes when invoking the compress/decompress commands.
The format strings are placed in single quotes. mutt_system() invokes sh, so escape the single quotes using bourne-shell syntax: '\''
Diffstat (limited to 'compress.c')
-rw-r--r--compress.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/compress.c b/compress.c
index 8ef4525e..ae8d563b 100644
--- a/compress.c
+++ b/compress.c
@@ -296,6 +296,49 @@ mutt_free_compress_info (CONTEXT *ctx)
}
/**
+ * escape_path - Escapes single quotes in a path for a command string.
+ * @src - the path to escape.
+ *
+ * Returns: a pointer to the escaped string.
+ */
+static char *
+escape_path (char *src)
+{
+ static char dest[HUGE_STRING];
+ char *destp = dest;
+ int destsize = 0;
+
+ if (!src)
+ return NULL;
+
+ while (*src && (destsize < sizeof(dest) - 1))
+ {
+ if (*src != '\'')
+ {
+ *destp++ = *src++;
+ destsize++;
+ }
+ else
+ {
+ /* convert ' into '\'' */
+ if (destsize + 4 < sizeof(dest))
+ {
+ *destp++ = *src++;
+ *destp++ = '\\';
+ *destp++ = '\'';
+ *destp++ = '\'';
+ destsize += 4;
+ }
+ else
+ break;
+ }
+ }
+ *destp = '\0';
+
+ return dest;
+}
+
+/**
* cb_format_str - Expand the filenames in the command string
* @dest: Buffer in which to save string
* @destlen: Buffer length
@@ -328,11 +371,11 @@ cb_format_str (char *dest, size_t destlen, size_t col, int cols, char op, const
{
case 'f':
/* Compressed file */
- snprintf (dest, destlen, "%s", ctx->realpath);
+ snprintf (dest, destlen, "%s", NONULL (escape_path (ctx->realpath)));
break;
case 't':
/* Plaintext, temporary file */
- snprintf (dest, destlen, "%s", ctx->path);
+ snprintf (dest, destlen, "%s", NONULL (escape_path (ctx->path)));
break;
}
return src;