output: add must_put_err() utility function

This function deals situation when mustach put happens before enter, that is
a sign of an invalid input template.  Good side of adding this function is
that dhcpd-pools does not need to modify code provided by Jose.

Reference: 66183bc7c7
Proposed-by: José Bollo <jobol@nonadev.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-11 09:00:33 +00:00
parent 4fc4bcd083
commit e4baff79bd
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 11 additions and 4 deletions

View file

@ -61,11 +61,20 @@ struct expl {
static int must_enter(void *closure, const char *name);
static int must_leave(void *closure);
/* This can be called when template is invalid end put happens before enter. */
int must_put_err(void *closure __attribute__ ((unused)),
const char *name __attribute__ ((unused)),
int escape __attribute__ ((unused)),
FILE *file __attribute__ ((unused)))
{
return MUSTACH_ERROR_SYSTEM;
}
/* Set mustach function pointers. */
static struct mustach_itf itf = {
.start = NULL,
.enter = must_enter,
.put = NULL,
.put = must_put_err,
.next = NULL,
.leave = must_leave
};

View file

@ -38,7 +38,7 @@ static int getpartial(struct mustach_itf *itf, void *closure, const char *name,
*result = NULL;
file = open_memstream(result, &size);
if (itf->put == NULL || file == NULL)
if (file == NULL)
rc = MUSTACH_ERROR_SYSTEM;
else {
rc = itf->put(closure, name, 0, file);
@ -192,8 +192,6 @@ static int process(const char *template, struct mustach_itf *itf, void *closure,
default:
/* replacement */
if (emit) {
if (itf->put == NULL)
return MUSTACH_ERROR_SYSTEM;
rc = itf->put(closure, name, c != '&', file);
if (rc < 0)
return rc;