From 246f8e18fd52417dd768c4afe68e8a429a9d83f7 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 25 Nov 2019 23:03:30 -0500 Subject: Fixed a crash Certain conditions on an if statement could cause a crash, bug introduced when adding errors everywhere a few patches ago. --- src/ctemplates.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ctemplates.c b/src/ctemplates.c index 3209bf4..ab746ee 100644 --- a/src/ctemplates.c +++ b/src/ctemplates.c @@ -1078,32 +1078,57 @@ render_if(struct TMPL_templates* t, struct TMPL_varlist* varlist){ if(err == MAP_OK){ //These two if statements can't be combined because of //the condition for the elseif + //If we found the value without a test value, or we have + //a test value and it's correct, do the true branch if(testval == NULL || strcmp(vi->item.s, testval) == 0){ nt->roottag = t->cursor->TMPL_tag.ifelse.tbranch; nt->cursor = nt->roottag; err = TMPL_render_helper(nt,varlist); + if(err){ + goto cleanup; + } if(nt->jumping) t->cursor = nt->cursor; t->breaks += nt->breaks; t->continues = nt->continues; t->jumping = nt->jumping; }else{ - + //Our test value is not empty, and we found the value, + //but it's not the correct value. + nt->roottag = t->cursor->TMPL_tag.ifelse.fbranch; + nt->cursor = nt->roottag; + err = TMPL_render_helper(nt,varlist); + if(err){ + goto cleanup; + } + if(nt->jumping) + t->cursor = nt->cursor; + t->breaks += nt->breaks; + t->continues = nt->continues; + t->jumping = nt->jumping; + err = 0; } - }else if(t->cursor->TMPL_tag.ifelse.fbranch != NULL){ nt->roottag = t->cursor->TMPL_tag.ifelse.fbranch; nt->cursor = nt->roottag; err = TMPL_render_helper(nt,varlist); + if(err){ + goto cleanup; + } if(nt->jumping) t->cursor = nt->cursor; t->breaks += nt->breaks; t->continues = nt->continues; t->jumping = nt->jumping; + err = 0; }else{ + //Could not find value, and we don't have a false branch, + //do nothing + err = 0; } - free(nt); advance_cursor(t); +cleanup: + free(nt); return err; } -- cgit v1.2.3-70-g09d2