From f3617a1cf3c0a6f1f64d0445cedcaba0e68cff8e Mon Sep 17 00:00:00 2001 From: cpq Date: Fri, 18 Aug 2023 20:33:57 +0100 Subject: [PATCH] Add integer overflow protection --- mongoose.c | 1 + src/http.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mongoose.c b/mongoose.c index cb7f5d77..e2ae6d46 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1533,6 +1533,7 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) { hm->body.len = 0; hm->message.len = (size_t) req_len; } + if (hm->message.len < (size_t) req_len) return -1; // Overflow protection return req_len; } diff --git a/src/http.c b/src/http.c index b63752f5..1ee482b0 100644 --- a/src/http.c +++ b/src/http.c @@ -301,6 +301,7 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) { hm->body.len = 0; hm->message.len = (size_t) req_len; } + if (hm->message.len < (size_t) req_len) return -1; // Overflow protection return req_len; }