output: make mustach processing more robust

Fix issues found with afl-fuzz.  It is a pity I had to change mustach.c it
is no longer exactly the same as upstream.  Lets see if Jose will accept
these changes.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-09 18:51:29 +00:00
parent 2ec953858b
commit 66183bc7c7
No known key found for this signature in database
GPG key ID: A9553245FDE9B739

View file

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