mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Fix core dumps while handling templates
Conky would dump core when encountering templates with no parameters (both $templateX and ${templateX}) and when the line contained improperly nested {}. Signed-off-by: Brenden Matthews <brenden@rty.ca>
This commit is contained in:
parent
b7f2424077
commit
8540821323
76
src/conky.c
76
src/conky.c
@ -2954,7 +2954,8 @@ static char *backslash_escape(const char *src, char **templates, unsigned int te
|
|||||||
*/
|
*/
|
||||||
static char *handle_template(const char *tmpl, const char *args)
|
static char *handle_template(const char *tmpl, const char *args)
|
||||||
{
|
{
|
||||||
char *args_dup, *p, *p_old;
|
char *args_dup = NULL;
|
||||||
|
char *p, *p_old;
|
||||||
char **argsp = NULL;
|
char **argsp = NULL;
|
||||||
unsigned int argcnt = 0, template_idx, i;
|
unsigned int argcnt = 0, template_idx, i;
|
||||||
char *eval_text;
|
char *eval_text;
|
||||||
@ -2963,28 +2964,30 @@ static char *handle_template(const char *tmpl, const char *args)
|
|||||||
(template_idx > 9))
|
(template_idx > 9))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
args_dup = strdup(args);
|
if(args) {
|
||||||
p = args_dup;
|
args_dup = strdup(args);
|
||||||
while (*p) {
|
p = args_dup;
|
||||||
while (*p && (*p == ' ' && *(p - 1) != '\\'))
|
while (*p) {
|
||||||
p++;
|
while (*p && (*p == ' ' && *(p - 1) != '\\'))
|
||||||
if (*(p - 1) == '\\')
|
p++;
|
||||||
p--;
|
if (*(p - 1) == '\\')
|
||||||
p_old = p;
|
p--;
|
||||||
while (*p && (*p != ' ' || *(p - 1) == '\\'))
|
p_old = p;
|
||||||
p++;
|
while (*p && (*p != ' ' || *(p - 1) == '\\'))
|
||||||
if (*p) {
|
p++;
|
||||||
(*p) = '\0';
|
if (*p) {
|
||||||
p++;
|
(*p) = '\0';
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
argsp = realloc(argsp, ++argcnt * sizeof(char *));
|
||||||
|
argsp[argcnt - 1] = p_old;
|
||||||
|
}
|
||||||
|
for (i = 0; i < argcnt; i++) {
|
||||||
|
char *tmp;
|
||||||
|
tmp = backslash_escape(argsp[i], NULL, 0);
|
||||||
|
DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
|
||||||
|
argsp[i] = tmp;
|
||||||
}
|
}
|
||||||
argsp = realloc(argsp, ++argcnt * sizeof(char *));
|
|
||||||
argsp[argcnt - 1] = p_old;
|
|
||||||
}
|
|
||||||
for (i = 0; i < argcnt; i++) {
|
|
||||||
char *tmp;
|
|
||||||
tmp = backslash_escape(argsp[i], NULL, 0);
|
|
||||||
DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
|
|
||||||
argsp[i] = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eval_text = backslash_escape(template[template_idx], argsp, argcnt);
|
eval_text = backslash_escape(template[template_idx], argsp, argcnt);
|
||||||
@ -3019,25 +3022,36 @@ static char *find_and_replace_templates(const char *inbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*(p + 1) == '{') {
|
if (*(p + 1) == '{') {
|
||||||
templ = p + 2;
|
p += 2;
|
||||||
while (*p != ' ')
|
templ = p;
|
||||||
|
while (*p && *p != ' ' && *p != '{' && *p != '}')
|
||||||
p++;
|
p++;
|
||||||
*(p++) = '\0';
|
if (*p == '}')
|
||||||
args = p;
|
args = NULL;
|
||||||
|
else
|
||||||
|
args = p;
|
||||||
|
|
||||||
stack = 1;
|
stack = 1;
|
||||||
while (stack > 0) {
|
while (*p && stack > 0) {
|
||||||
p++;
|
|
||||||
if (*p == '{')
|
if (*p == '{')
|
||||||
stack++;
|
stack++;
|
||||||
else if (*p == '}')
|
else if (*p == '}')
|
||||||
stack--;
|
stack--;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if (stack == 0) {
|
||||||
|
// stack is empty. that means the previous char was }, so we zero it
|
||||||
|
*(p - 1) = '\0';
|
||||||
|
} else {
|
||||||
|
// we ran into the end of string without finding a closing }, bark
|
||||||
|
CRIT_ERR("cannot find a closing '}' in template expansion");
|
||||||
}
|
}
|
||||||
*(p++) = '\0';
|
|
||||||
} else {
|
} else {
|
||||||
templ = p + 1;
|
templ = p + 1;
|
||||||
while (*p != ' ')
|
while (*p && *p != ' ')
|
||||||
p++;
|
p++;
|
||||||
*(p++) = '\0';
|
if(*p)
|
||||||
|
*(p++) = '\0';
|
||||||
args = NULL;
|
args = NULL;
|
||||||
}
|
}
|
||||||
tmpl_out = handle_template(templ, args);
|
tmpl_out = handle_template(templ, args);
|
||||||
|
Loading…
Reference in New Issue
Block a user