mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: David CARLIER <devnexen@gmail.com>, g@port70.net
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH 1/1] reallocarray casting overflow check explicitally
Date: Tue, 11 May 2021 09:33:06 +0200	[thread overview]
Message-ID: <20210511073306.GQ2799122@port70.net> (raw)
In-Reply-To: <CA+XhMqy0tqvhNv35ZB9JV4FVfEMHE_gT8FeW_6An9Dv6khP7EQ@mail.gmail.com>

* David CARLIER <devnexen@gmail.com> [2021-05-10 20:48:26 +0100]:
> From 04e3caa580cfe501ad00d85d63040de329962823 Mon Sep 17 00:00:00 2001
> From: David Carlier <devnexen@gmail.com>
> Date: Mon, 10 May 2021 20:45:12 +0100
> Subject: [PATCH] reallocarray overflow check cast to size_t
> 
> ---
>  src/malloc/reallocarray.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c
> index 4a6ebe46..2556c917 100644
> --- a/src/malloc/reallocarray.c
> +++ b/src/malloc/reallocarray.c
> @@ -4,7 +4,7 @@
>  
>  void *reallocarray(void *ptr, size_t m, size_t n)
>  {
> -	if (n && m > -1 / n) {
> +	if (n && m > (size_t)-1 / n) {

you need to explain this change more i think.

the usual arithmetic conversion rules of c already convert both
operands of / to size_t, unless size_t has lower conversion rank
than signed int, but such a system would have problems because
size_t was always promoted to int so you would need a lot more
casts in musl (and other software) to avoid signed int overflow
and negative arithmetics.

>  		errno = ENOMEM;
>  		return 0;
>  	}
> -- 
> 2.20.1
> 


  reply	other threads:[~2021-05-11  7:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 19:48 David CARLIER
2021-05-11  7:33 ` Szabolcs Nagy [this message]
2021-05-11 13:03   ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210511073306.GQ2799122@port70.net \
    --to=nsz@port70.net \
    --cc=devnexen@gmail.com \
    --cc=g@port70.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).