mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Difference between -O2 and -g
Date: Fri, 26 Oct 2012 13:58:49 -0400	[thread overview]
Message-ID: <20121026175849.GZ254@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAPW=hRTt3gcLjf-ZnEDuG2_rQA-5aJbZ=fsJFU9Ejp7Ue1dY4g@mail.gmail.com>

On Fri, Oct 26, 2012 at 02:44:36PM +0800, Brian Wang wrote:
> >> The failed call is within dix/colormap.c:CreateColormap().
> >>
> >> Thanks for helping.  I really appreciate it.
> >
> > I would check out Xext/security.c SecurityResource() and see if you
> > can figure out what it's doing. That appears to be the callback that's
> > getting called. You might want to check and see if there are any
> > others that could be registered; this could be done by grepping for
> > XaceRegister.*RESOURCE, which I didn't do because I'm browsing the
> > source online and the web interface seems to lack grep.
> >
> 
> With a bit of digging, I found the source code of this oldish xserver
> may trigger an undefined behaviour.
> When calling XaceHook(int hook, ...), the switch case looks like this:
> ---------
> switch (hook)
>     {
> 	case XACE_RESOURCE_ACCESS: {
> 	    XaceResourceAccessRec rec = {
> 		va_arg(ap, ClientPtr),
> 		va_arg(ap, XID),
> 		va_arg(ap, RESTYPE),
> 		va_arg(ap, pointer),
> 		va_arg(ap, RESTYPE),
> 		va_arg(ap, pointer),
> 		va_arg(ap, Mask),
> 		Success /* default allow */
> 	    };
> 	    calldata = &rec;
> 	    prv = &rec.status;
> 	    break;
> 	}
> ---------
> I think gcc-4.7.2 looks at 'rec' and thinks it is local to the switch
> case and optimizes it away.  However, 'prv' will be accessed
> down below outside the case.
> I do not know whose fault this is (most likely this piece of code),
> but certainly not musl's. :-)

Nice catch. This is definitely a case of invoking undefined behavior.
Actually, gcc should have issued a big warning about this (letting a
pointer to an automatic object escape its lifetime); I'm surprised it
didn't. Unfortunately I was looking at the current version of the code
which does not have this bug.

Rich


      reply	other threads:[~2012-10-26 17:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26  1:31 Brian Wang
2012-10-26  1:40 ` Rich Felker
2012-10-26  2:04   ` Brian Wang
2012-10-26  2:21     ` Brian Wang
2012-10-26  2:32     ` Rich Felker
2012-10-26  2:47       ` Brian Wang
2012-10-26  2:55         ` Rich Felker
2012-10-26  3:01           ` Brian Wang
2012-10-26  3:19             ` Rich Felker
2012-10-26  6:44               ` Brian Wang
2012-10-26 17:58                 ` Rich Felker [this message]

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=20121026175849.GZ254@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --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).