From 297448cfffff809782ec704ae03ab64e9addeb76 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 16 May 2020 23:23:40 +0100 Subject: make about handler ssenddataf cope with longer data --- content/fetchers/about.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'content') diff --git a/content/fetchers/about.c b/content/fetchers/about.c index 2534d070d..71249e85e 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -132,6 +132,7 @@ fetch_about_send_header(struct fetch_about_context *ctx, const char *fmt, ...) static nserror ssenddataf(struct fetch_about_context *ctx, const char *fmt, ...) { char buffer[1024]; + char *dbuff; fetch_msg msg; va_list ap; int slen; @@ -142,18 +143,39 @@ static nserror ssenddataf(struct fetch_about_context *ctx, const char *fmt, ...) va_end(ap); - if (slen >= (int)sizeof(buffer)) { + if (slen < (int)sizeof(buffer)) { + msg.type = FETCH_DATA; + msg.data.header_or_data.buf = (const uint8_t *) buffer; + msg.data.header_or_data.len = slen; + + if (fetch_about_send_callback(&msg, ctx)) { + return NSERROR_INVALID; + } + + return NSERROR_OK; + } + + dbuff = malloc(slen + 1); + if (dbuff == NULL) { return NSERROR_NOSPACE; } + va_start(ap, fmt); + + slen = vsnprintf(dbuff, slen + 1, fmt, ap); + + va_end(ap); + msg.type = FETCH_DATA; - msg.data.header_or_data.buf = (const uint8_t *) buffer; + msg.data.header_or_data.buf = (const uint8_t *)dbuff; msg.data.header_or_data.len = slen; if (fetch_about_send_callback(&msg, ctx)) { + free(dbuff); return NSERROR_INVALID; } + free(dbuff); return NSERROR_OK; } -- cgit v1.2.3