From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2537 Path: news.gmane.org!not-for-mail From: John Spencer Newsgroups: gmane.linux.lib.musl.general Subject: Re: NULL Date: Wed, 09 Jan 2013 14:36:43 +0100 Message-ID: <50ED726B.7010201@barfooze.de> References: <50ED4E45.6050801@barfooze.de> <20130109121832.GL4468@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1357738659 4706 80.91.229.3 (9 Jan 2013 13:37:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Jan 2013 13:37:39 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2538-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 09 14:37:55 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Tsvqp-0008I4-Kp for gllmg-musl@plane.gmane.org; Wed, 09 Jan 2013 14:37:52 +0100 Original-Received: (qmail 16225 invoked by uid 550); 9 Jan 2013 13:37:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 16217 invoked from network); 9 Jan 2013 13:37:35 -0000 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Mail/1.0 In-Reply-To: <20130109121832.GL4468@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:2537 Archived-At: On 01/09/2013 01:18 PM, Szabolcs Nagy wrote: > * John Spencer [2013-01-09 12:02:29 +0100]: >> at this point the issue in evince is not fixed, i still need to >> create a patch based on their current git master, subscribe to their >> ML, send them the patch and hope that they haven't changed their >> mind. > i think you are overcomplicating this issue > > this is clearly a violation of the standard and that's what > you should tell to the maintainers: > > using NULL in the argument of variadic functions is ub both > in c and c++ many developers don't care about the standard. they take the stance: "works for me, if you want it patched then do it yourself and we'll eventually merge" > the problem is worse in c++ because it actually breaks code > in practice with the usual c++ definition of NULL, in c the > usual definition happens to work > >> so for me, there are 3 options how to deal with issue in the future: >> >> 1) go into the trouble of debugging all future C++ apps i will port, > i think this issue should be catched with automated tools, not debugging: > static code analyzer or runtime instrumentation of vararg functions yes, as i proposed in 3) >> (as a side note: when i googled for g_signal_emit, i found multiple >> bug reports to multiple projects, of which the backtraces showed >> exactly the kind of varargs UB that i encountered. >> all of them were not fixed, but merely worked around. apparently the >> developers of these projects didnt find the real cause of their >> bugs. >> this is not unlikely, as it is very hard to find out whats going on. >> https://bugs.launchpad.net/compiz/+bug/932382 >> https://trac.transmissionbt.com/ticket/1135 ... ) > may be this should get a bit more publicity, > it's an easy to fix bug yes, once you know the details, it's easy to fix. but when you don't, you'll have a hard time figuring out where the segfault comes from. i agree that this should get more publicity. >> 2) change musl so it is compatible with those apps. this would mean: >> #if defined(__GNUC__)&& defined(__cplusplus__) >> #define NULL __null > i think this is not needed, you can have a definition > in c++ that "happens to work" just like the (void*)0 > in c: > > #define NULL 0L yes, that'll work as well. > but this is just a workaround, the bugs still need to be fixed again, some ppl don't agree, even if you cite the standard. i even heard things like "using a cast is ugly (or C'ish), we prefer NULL" > (in c++11 we could use nullptr which has std::nullptr_t type > which converts to (void*)0 in vararg context, but c++11 is not > widely used yet) > >> 3) create some kind of code analysis tool that will scan C++ code > i don't know any good open source static code analyzer for > c and c++, maybe the clang based one can do the job did you look at cppcheck ? i think this could be the right tool for the job. if we raise awareness of the issue, i'm sure they'll add a check for this. > i tried splint but that does not catch it > > catching null pointers in general can be tricky as 0 may be a > valid argument to a variadic function and the code analyzer has > no way to tell if it's meant to be a pointer or not > > but if NULL is used without a cast then that's an error both in > c and c++ as both languages allow various different definitions > of NULL which may have different size and representation in > vararg context > >> i'm welcoming any comments on the issue. i'm especially interested >> what the gentoo developers think. > i wonder what makes them special :) > well, from what i heard on IRC they started to work on a musl port 2 weeks ago (but it got silent since...). since they have likely more packages than sabotage (350) this issue could cause them major pain.