Re: [PATCH v6 10/12] http: replace unsafe size_t multiplication with st_mult
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jan 18, 2023, 11:38 UTC
- Message-ID
- <230118.863588xeat.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <cc9a220ed1f12aef2f4df940e71adc1fad917a6b.1674012618.git.gitgitgadget@gmail.com>
On Wed, Jan 18 2023, Matthew John Cheetham via GitGitGadget wrote:
Show 33 quoted lines
> From: Matthew John Cheetham <mjcheetham@outlook.com>
>
> Replace direct multiplication of two size_t parameters in curl response
> stream handling callback functions with `st_mult` to guard against
> overflows.
>
> Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
> ---
> http.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/http.c b/http.c
> index 8a5ba3f4776..a2a80318bb2 100644
> --- a/http.c
> +++ b/http.c
> @@ -146,7 +146,7 @@ static int http_schannel_use_ssl_cainfo;
>
> size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
> {
> - size_t size = eltsize * nmemb;
> + size_t size = st_mult(eltsize, nmemb);
> struct buffer *buffer = buffer_;
>
> if (size > buffer->buf.len - buffer->posn)
> @@ -176,7 +176,7 @@ curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
>
> size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
> {
> - size_t size = eltsize * nmemb;
> + size_t size = st_mult(eltsize, nmemb);
> struct strbuf *buffer = buffer_;
>
> strbuf_add(buffer, ptr, size);This is a really worthwhile fix, but shouldn't this be split into its own stand-alone patch? It applies on "master", and seems like something that's a good idea outside of this "test-http-server" topic.