diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-02-19 23:00:56 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-02-19 23:00:56 +0100 |
| commit | afe0681c0b26bb64bad55d7e86770f346cfa043e (patch) | |
| tree | 420dbf3084332bf1750d0986ea118b427aed7364 /http.c | |
| parent | 9d9e0c2979f43297b2ebbf84f14f064f3f9ced0e (diff) | |
Limit maximum multipart/form-data pairs and files
A malicious user could inject an infinite number of empty files or
key/value pairs into a request in order to exhaust the device's
resources.
Diffstat (limited to 'http.c')
| -rw-r--r-- | http.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1728,7 +1728,16 @@ static int apply_from_file(struct http_ctx *const h, struct form *const f) m->f = NULL; + const struct http_cfg_post *const cfg = &h->cfg.post; const size_t n = m->nfiles + 1; + + if (n > cfg->max_files) + { + fprintf(stderr, "%s: exceeded maximum number of files (%zu)\n", + __func__, cfg->max_files); + return 1; + } + struct http_post_file *const files = realloc(m->files, n * sizeof *m->files); @@ -1777,10 +1786,17 @@ static int apply_from_mem(struct http_ctx *const h, struct form *const f) if (name_exists(m, f)) return 1; + const struct http_cfg_post *const cfg = &h->cfg.post; struct http_post_pair *pairs, *p; const size_t n = m->npairs + 1; - if (!(f->value = strndup(h->line, m->written))) + if (n > cfg->max_pairs) + { + fprintf(stderr, "%s: exceeded maximum number of pairs (%zu)\n", + __func__, cfg->max_pairs); + return 1; + } + else if (!(f->value = strndup(h->line, m->written))) { fprintf(stderr, "%s: strndup(3): %s\n", __func__, strerror(errno)); return -1; |
