public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>,
	Florian Weimer <fweimer@redhat.com>,
	libc-alpha@sourceware.org
Subject: Re: [PATCH] malloc: Simplify implementation of __malloc_assert
Date: Thu, 21 Jul 2022 08:36:21 -0400	[thread overview]
Message-ID: <c9ff4071-4609-e14e-8c31-2ca83e420328@redhat.com> (raw)
In-Reply-To: <d8dde8c6-ac0c-a1fc-e7f8-995fa597a872@gotplt.org>

On 7/21/22 07:43, Siddhesh Poyarekar wrote:
> On 2022-07-21 06:34, Florian Weimer via Libc-alpha wrote:
>> It is prudent not to run too much code after detecting heap
>> corruption, and __fxprintf is really complex.  The line number
>> and file name do not carry much information, so it is not included
>> in the error message.  (__libc_message only supports %s formatting.)
>> The function name and assertion should provide some context.
>>
>> Tested on i686-linux-gnu and x86_64-linux-gnu.  Also emulated the
>> __libc_message call using GDB, and it produced the expected output.
>>
>> Thanks,
>> Florian
>> ---
> 
> LGTM.
> 
> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
 
Approved as RM for glibc 2.36.

This avoids us calling malloc down the failing path.

>   malloc/malloc.c | 15 +++++----------
>>   1 file changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/malloc/malloc.c b/malloc/malloc.c
>> index 12908b8f97..bd3c76ed31 100644
>> --- a/malloc/malloc.c
>> +++ b/malloc/malloc.c
>> @@ -292,19 +292,14 @@
>>   # define __assert_fail(assertion, file, line, function)            \
>>        __malloc_assert(assertion, file, line, function)
>>   -extern const char *__progname;
>> -
>> -static void
>> +_Noreturn static void
>>   __malloc_assert (const char *assertion, const char *file, unsigned int line,
>>            const char *function)
>>   {
>> -  (void) __fxprintf (NULL, "%s%s%s:%u: %s%sAssertion `%s' failed.\n",
>> -             __progname, __progname[0] ? ": " : "",
>> -             file, line,
>> -             function ? function : "", function ? ": " : "",
>> -             assertion);
>> -  fflush (stderr);
>> -  abort ();
>> +  __libc_message (do_abort, "\
>> +Fatal glibc error: malloc assertion failure in %s: %s\n",
>> +          function, assertion);
>> +  __builtin_unreachable ();
>>   }
>>   #endif
>>   #endif
>>
> 


-- 
Cheers,
Carlos.


  reply	other threads:[~2022-07-21 12:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 10:34 Florian Weimer
2022-07-21 11:43 ` Siddhesh Poyarekar
2022-07-21 12:36   ` Carlos O'Donell [this message]
2022-07-21 13:10 ` Adhemerval Zanella Netto
2022-07-21 13:24   ` Adhemerval Zanella Netto
2022-07-21 13:28     ` Florian Weimer
2022-07-21 13:26   ` Florian Weimer
2022-07-21 13:40     ` Adhemerval Zanella Netto
2022-07-22 11:38       ` Florian Weimer

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=c9ff4071-4609-e14e-8c31-2ca83e420328@redhat.com \
    --to=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@gotplt.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).