Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fcbizmykmll6wf3n4wzsj3hhumcdgadlcvkhgstx7536d4z2o6@hsmjdatgeydg>
Date: Mon, 16 Jun 2025 23:21:06 +0200
From: Alejandro Colomar <alx@...nel.org>
To: enh <enh@...gle.com>
Cc: libc-alpha@...rceware.org, 
	наб <nabijaczleweli@...ijaczleweli.xyz>, Paul Eggert <eggert@...ucla.edu>, 
	Robert Seacord <rcseacord@...il.com>, musl@...ts.openwall.com, Bruno Haible <bruno@...sp.org>, 
	bug-gnulib@....org, JeanHeyd Meneide <phdofthehouse@...il.com>
Subject: Re: BUG: realloc(p,0) should be consistent with malloc(0)

Hi Elliott,

On Mon, Jun 16, 2025 at 12:40:18PM -0400, enh wrote:
> On Mon, Jun 16, 2025 at 7:55 AM Alejandro Colomar <alx@...nel.org> wrote:
> >
> > Hi!
> >
> > For context, the old discussion was in this thread:
> > <https://inbox.sourceware.org/libc-alpha/nbyurzcgzgd5rdybbi4no2kw5grrc32k63svf7oq73nfcbus5r@77gry66kpqfr/>
> >
> > Also for context, here's the excellent research by наб about malloc(0)
> > and realloc(p, 0) in historic UNIX systems and their descendents:
> > <https://nabijaczleweli.xyz/content/blogn_t/017-malloc0.html>
> >
> > We discussed last year about realloc(p, 0) being problematic currently
> > in glibc.  Ideally, realloc(p, n) should be consistent with malloc(n)
> > in that:
> >
> > -  It is equivalent to free(p) and malloc(n), regardless of the value of
> >    n, including when it is 0, and regardless of p, including when it is
> >    NULL.
> 
> android has these tests in the compatibility test suite (cts):
> 
> TEST(malloc, realloc_nullptr_0) {
>   // realloc(nullptr, size) is actually malloc(size).
>   void* p = realloc(nullptr, 0);
>   ASSERT_TRUE(p != nullptr);
>   free(p);
> }
> 
> TEST(malloc, realloc_0) {
>   void* p = malloc(1024);
>   ASSERT_TRUE(p != nullptr);
>   // realloc(p, 0) is actually free(p).
>   void* p2 = realloc(p, 0);
>   ASSERT_TRUE(p2 == nullptr);
> }

Hmmm, then Bionic is broken, like glibc.  The first test above is good,
but the second is not.  realloc(p, 0) should be free(p) and malloc(0).

That's what we changed in gnulib last year.  I suggest that you apply
the same fix.  If you need convincing, I can try writing a summary of
the old thread.


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.