Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2016-10-21 16:01:11 +01:00
3 changed files with 30 additions and 18 deletions

18
cmd.c
View File

@ -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);