From 5be3ffdd3bfd96b314509f6f03e211e309d0fef3 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 9 Sep 2023 02:22:00 +0200 Subject: http: Use null-terminated string for POST data application/x-www-form-urlencoded-data is (or should be) always text, so it is preferrable to define struct http_post member "data" as a null- terminated string. For applications already making this assumption, this change should now remove the need for string duplication. --- http.c | 6 +++--- include/slweb/http.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/http.c b/http.c index 9274ccb..73c7b67 100644 --- a/http.c +++ b/http.c @@ -1716,7 +1716,7 @@ static int read_body_to_mem(struct http_ctx *const h, bool *const close) struct ctx *const c = &h->ctx; struct post *const p = &c->post; - if (p->read >= sizeof h->line) + if (p->read >= sizeof h->line - 1) { fprintf(stderr, "%s: exceeded maximum length\n", __func__); return 1; @@ -1738,11 +1738,11 @@ static int read_body_to_mem(struct http_ctx *const h, bool *const close) .resource = c->resource, .u.post = { - .data = h->line, - .n = p->len + .data = h->line } }; + h->line[p->len] = '\0'; return send_payload(h, &pl); } diff --git a/include/slweb/http.h b/include/slweb/http.h index 7f5935a..a9c9751 100644 --- a/include/slweb/http.h +++ b/include/slweb/http.h @@ -25,8 +25,8 @@ struct http_payload struct http_post { bool expect_continue; - const void *data; - size_t n, nfiles, npairs; + const char *data; + size_t nfiles, npairs; const struct http_post_pair { -- cgit v1.2.3