mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Matt Avery <mavery@akamai.com>
To: musl@lists.openwall.com
Subject: Re: Results of static analysis with clang static analyser
Date: Fri, 25 Sep 2015 11:35:27 -0400	[thread overview]
Message-ID: <560569BF.4020505@akamai.com> (raw)
In-Reply-To: <1443079354.23868.25.camel@inria.fr>

[-- Attachment #1: Type: text/plain, Size: 1966 bytes --]

I'm not sure how keen you are to use asserts, but adding them helps the static analyzer not evaluate impossible paths. From the docs <http://clang-analyzer.llvm.org/scan-build.html>:

ALWAYS analyze a project in its "debug" configuration

Most projects can be built in a "debug" mode that enables assertions.
Assertions are picked up by the static analyzer to prune infeasible paths, which
in some cases can greatly reduce the number of false positives (bogus error
reports) emitted by the tool.

Adding an assert(tsd != 0) after the arithmetic operation, or even better,  assert(stack > __pthread_tsd_size) before should be enough?  
-Matt



On 09/24/2015 03:22 AM, Jens Gustedt wrote:
> Am Mittwoch, den 23.09.2015, 20:34 -0400 schrieb Rich Felker:
>> On Wed, Sep 23, 2015 at 10:02:51PM +0200, Jens Gustedt wrote:
>>> The one in pthread_create I always struggle with. I remember that I
>>> had myself once convinced (or was it you?) that the bad case can't
>>> happen, but I was not able to reproduce the argument spontaneously.
>> From my perspective, this one is simply a bug in the static analysis.
>> At line 218, pointer arithmetic was performed on `stack` to get `tsd`.
>> If `stack` were null this would be UB, and if `stack` is not null then
>> you cannot get a null pointer without the arithmetic having invoked
>> UB, so you can conclude that `tsd` is not null.
> I wouldn'd call this a bug. This also assumes that the analyser has do
> "know" from somewhere that `stack` is a pointer that is sufficiently
> far from the 0 address, so the result of the arithmetic can never be a
> 0 valued pointer.
>
> So the problem here is that we use a pointer value that is the result
> of arithmetic to hold the state of a conditional execution.
>
> AFAICS, we could completely avoid that by placing a goto after line
> 220 to jump to line 251. Then the initialization of tsd and the `if
> (!tsd)` conditional (not the code inside) could be omitted.
>
> Jens
>
>


[-- Attachment #2: Type: text/html, Size: 2572 bytes --]

  parent reply	other threads:[~2015-09-25 15:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23  5:58 Khem Raj
2015-09-23 19:38 ` Rich Felker
2015-09-23 20:02   ` Jens Gustedt
2015-09-24  0:34     ` Rich Felker
2015-09-24  7:22       ` Jens Gustedt
2015-09-24  8:51         ` [PATCH] help static analysis by avoiding to hold state in a pointer that is subject to arithmetic Jens Gustedt
2015-09-25 15:35         ` Matt Avery [this message]
2015-09-25 21:37           ` Results of static analysis with clang static analyser Jens Gustedt
2015-09-23 20:11 ` Szabolcs Nagy
2015-09-24  6:35   ` Rich Felker
2015-09-23 20:34 ` Szabolcs Nagy

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=560569BF.4020505@akamai.com \
    --to=mavery@akamai.com \
    --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).