diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-04 02:34:55 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-04 03:03:22 +0100 |
| commit | c033b3006cb90e7396403d7ac3d2fb6f08a91028 (patch) | |
| tree | e446ba12dac1ee093f9f62354263ef9c935e8726 | |
| parent | 62bdf9f72f6a65b76bbb97ffa467e16217646cbc (diff) | |
| download | slcl-c033b3006cb90e7396403d7ac3d2fb6f08a91028.tar.gz | |
http.c: Improve error detection for strotull(3)
set_length relies on user input to determine Content-Length, so it
should be considered unreliable.
| -rw-r--r-- | http.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -562,7 +562,18 @@ failure: static int set_length(struct http_ctx *const h, const char *const len) { - h->ctx.post.len = strtoull(len, NULL, 10); + char *end; + + errno = 0; + h->ctx.post.len = strtoull(len, &end, 10); + + if (errno || *end != '\0') + { + fprintf(stderr, "%s: invalid length %s: %s\n", + __func__, len, strerror(errno)); + return 1; + } + return 0; } |
