aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2019-11-25 23:03:30 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2019-11-25 23:03:30 -0500
commit246f8e18fd52417dd768c4afe68e8a429a9d83f7 (patch)
tree7b370f248ded3f6fbca65fd43eb14150b53acda5
parenteaa22550d5f4c7dfbd4e7cdfec9559feff92b9e8 (diff)
downloadlibctemplates-246f8e18fd52417dd768c4afe68e8a429a9d83f7.tar.gz
libctemplates-246f8e18fd52417dd768c4afe68e8a429a9d83f7.tar.bz2
libctemplates-246f8e18fd52417dd768c4afe68e8a429a9d83f7.zip
Fixed a crash
Certain conditions on an if statement could cause a crash, bug introduced when adding errors everywhere a few patches ago.
-rw-r--r--src/ctemplates.c31
1 files changed, 28 insertions, 3 deletions
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;
}