aboutsummaryrefslogtreecommitdiff
path: root/cmd.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-10-21 16:01:11 +0100
committerThomas Adam <thomas@xteddy.org>2016-10-21 16:01:11 +0100
commit5f9ba2f223bcdc4770e56248d5f20e488ee11456 (patch)
tree01393e465ff04cafe3d7ffba2c10bd73096d2e89 /cmd.c
parentb951f0621caf154fbb73c99965b52b3bd4f9813c (diff)
parent8084a2c9e60b8cc0c32b55f23bfd7b839f082252 (diff)
downloadrtmux-5f9ba2f223bcdc4770e56248d5f20e488ee11456.tar.gz
rtmux-5f9ba2f223bcdc4770e56248d5f20e488ee11456.tar.bz2
rtmux-5f9ba2f223bcdc4770e56248d5f20e488ee11456.zip
Merge branch 'obsd-master'
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/cmd.c b/cmd.c
index 807c2de2..93091f53 100644
--- a/cmd.c
+++ b/cmd.c
@@ -652,8 +652,8 @@ char *
cmd_template_replace(const char *template, const char *s, int idx)
{
char ch, *buf;
- const char *ptr;
- int replaced;
+ const char *ptr, *cp;
+ int replaced, quoted;
size_t len;
if (strchr(template, '%') == NULL)
@@ -675,9 +675,17 @@ cmd_template_replace(const char *template, const char *s, int idx)
}
ptr++;
- len += strlen(s);
- buf = xrealloc(buf, len + 1);
- strlcat(buf, s, len + 1);
+ quoted = (*ptr == '%');
+ if (quoted)
+ ptr++;
+
+ buf = xrealloc(buf, len + (strlen(s) * 2) + 1);
+ for (cp = s; *cp != '\0'; cp++) {
+ if (quoted && *cp == '"')
+ buf[len++] = '\\';
+ buf[len++] = *cp;
+ }
+ buf[len] = '\0';
continue;
}
buf = xrealloc(buf, len + 2);