Skip to content

Commit a368c6c

Browse files
committed
various bug fixes for tmpl_dcursor.c
don't return freed pointer
1 parent 435f235 commit a368c6c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/lib/server/tmpl_dcursor.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ static inline CC_HINT(always_inline) void tmpl_cursor_nested_push(tmpl_dcursor_c
6666
fr_dlist_insert_tail(&cc->nested, ns);
6767
}
6868

69-
static inline CC_HINT(always_inline) tmpl_dcursor_nested_t *tmpl_cursor_nested_pop(tmpl_dcursor_ctx_t *cc)
69+
static inline CC_HINT(always_inline) bool tmpl_cursor_nested_pop(tmpl_dcursor_ctx_t *cc)
7070
{
7171
tmpl_dcursor_nested_t *ns = fr_dlist_pop_tail(&cc->nested);
7272

73+
if (!ns) return false;
74+
7375
if (ns != &cc->leaf) talloc_free(ns);
7476

75-
return ns;
77+
return true; /* at least one leaf */
7678
}
7779

7880
/** Initialise the evaluation context for traversing a group attribute
@@ -837,6 +839,7 @@ ssize_t tmpl_dcursor_print(fr_sbuff_t *out, tmpl_dcursor_ctx_t const *cc)
837839
}
838840

839841
ns = fr_dlist_head(&cc->nested);
842+
if (!ns) FR_SBUFF_SET_RETURN(out, &our_out);
840843

841844
/*
842845
* This also prints out the things we're looping over in nested?
@@ -862,13 +865,13 @@ ssize_t tmpl_dcursor_print(fr_sbuff_t *out, tmpl_dcursor_ctx_t const *cc)
862865

863866
FR_SBUFF_IN_STRCPY_RETURN(&our_out, ns->ar->da->name);
864867
FR_SBUFF_IN_CHAR_RETURN(&our_out, '[');
865-
FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%zd", ns->num - 1);
868+
FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%zu", ns->num - 1);
866869
FR_SBUFF_IN_CHAR_RETURN(&our_out, ']');
867870

868871
ns = fr_dlist_next(&cc->nested, ns);
869872
if (!ns) break;
870873

871-
FR_SBUFF_IN_CHAR_RETURN(&our_out, ']');
874+
FR_SBUFF_IN_CHAR_RETURN(&our_out, '.');
872875
}
873876

874877
FR_SBUFF_SET_RETURN(out, &our_out);

0 commit comments

Comments
 (0)