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
30
src/conky.c
30
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,6 +2964,7 @@ static char *handle_template(const char *tmpl, const char *args)
|
|||||||
(template_idx > 9))
|
(template_idx > 9))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if(args) {
|
||||||
args_dup = strdup(args);
|
args_dup = strdup(args);
|
||||||
p = args_dup;
|
p = args_dup;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
@ -2986,6 +2988,7 @@ static char *handle_template(const char *tmpl, const char *args)
|
|||||||
DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
|
DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
|
||||||
argsp[i] = tmp;
|
argsp[i] = tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
eval_text = backslash_escape(template[template_idx], argsp, argcnt);
|
eval_text = backslash_escape(template[template_idx], argsp, argcnt);
|
||||||
DBGP("substituted %s, output is '%s'", tmpl, eval_text);
|
DBGP("substituted %s, output is '%s'", tmpl, eval_text);
|
||||||
@ -3019,24 +3022,35 @@ 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 = NULL;
|
||||||
|
else
|
||||||
args = p;
|
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++;
|
||||||
|
if(*p)
|
||||||
*(p++) = '\0';
|
*(p++) = '\0';
|
||||||
args = NULL;
|
args = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user