aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-04 02:34:55 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-04 03:03:22 +0100
commitc033b3006cb90e7396403d7ac3d2fb6f08a91028 (patch)
treee446ba12dac1ee093f9f62354263ef9c935e8726
parent62bdf9f72f6a65b76bbb97ffa467e16217646cbc (diff)
downloadslcl-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.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/http.c b/http.c
index 448de24..dfb335d 100644
--- a/http.c
+++ b/http.c
@@ -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;
}