[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clang's memory sanitizer triggers in freea()

From: Tim Rühsen
Subject: Re: clang's memory sanitizer triggers in freea()
Date: Fri, 21 Jul 2017 22:13:50 +0200
User-agent: KMail/5.2.3 (Linux/4.11.0-1-amd64; KDE/5.28.0; x86_64; ; )

On Freitag, 21. Juli 2017 10:12:38 CEST Eric Blake wrote:
> On 07/21/2017 09:32 AM, Tim Rühsen wrote:
> > I am trying to use clang's address sanitizer on libidn2.
> >
> > It finds the use of uninitialized stack memory in malloca.c/freea()
> > (latest gnulib sources).
> >
> > It is this line which causes problems:
> >       if (((int *) p)[-1] == MAGIC_NUMBER)
> >
> > Is there anything that can/should be done in the code ?
> The access really is undefined per C rules, but safe in practice because
> of the size of the stack (the access may be out of bounds but is
> guaranteed not to fault), and while our decision based on the comparison
> can very-occasionally hit a false positive, our slow path code should
> correctly handle that.
> So the best we can do is annotate the code to state that we are
> intentionally stepping outside the bounds of safe C.
> > Maybe using clang's __attribute__((no_sanitize("memory"))) (see
> > https://clang.llvm.org/docs/MemorySanitizer.html#handling-external-code) ?
> If it works.  Patches welcome (I don't use clang enough myself to easily
> test the idea).

Here we go. The patch is simple and tested with clang-5.0 and gcc-6 and Debian
unstable. Works for me ;-)

Regards, Tim

Attachment: 0001-freea-Disable-clang-memory-sanitizer.patch
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]