<div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Message: 2<br>
Date: Thu, 31 Mar 2011 10:11:18 -0600<br>
From: Lenny Maiorani <lenny@Colorado.EDU><br>
Subject: Re: [cfe-commits] [PATCH] review request: mempcpy() checker<br>
        implementation for Static Analyzer<br>
To: <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
Message-ID: <<a href="mailto:4D94A7A6.6090805@colorado.edu">4D94A7A6.6090805@colorado.edu</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
On 03/30/2011 05:34 PM, Lenny Maiorani wrote:<br>
>> As for the modeling of mempcpy() (and memcpy() for that matter): the<br>
>> >>  behavior is that if NULL is passed as either the src or dst there will<br>
>> >>  be a NULL pointer dereference unless the number of bytes to copy is 0. I<br>
>> >>  am re-working the flow through evalCopyCommon to accurately reflect that.<br>
> >  I'm fine with that coming in with a later patch.  I just didn't know what the plan was.  Please feel free to use FIXME comments in the code to indicate "things to do" in the future.<br>
> ><br>
> >  If you want to regenerate the patch without tabs (and comments adjusted), I'll be happy to apply it!<br>
Attached is a revised patch. The tabs and comments are reformatted.<br>
<br>
More importantly, mempcpy() (and memcpy() for that matter) are being<br>
properly modelled. Meaning, if 0 bytes are to be copied it ignores the<br>
inputs. If the number of bytes to be copied is >0 then then the dest and<br>
src inputs are verified to be non-NULL. NULL triggers a bug report.<br>
Otherwise it is ensures that src and dest do not overlap and the dest<br>
buffer is large enough for the incoming bytes and triggers a bug report<br>
if it is not. Finally, it bind the return value (for mempcpy() is the<br>
byte after the last byte copied).<br>
<br>
<br>
-Lenny<br></blockquote><div><br>Hello Lenny,<br><br>regarding the issue of NULL source and destination: we've recently hit a bug at work where memcpy was called as:<br><br>memcpy(NULL, NULL, 0);<br><br>and it did crash on a segfault.<br>
<br>I asked for enlightenment on StackOverflow and after trudging through the C standard, it appears that there is no special case for the 0 bytes count:<br><br><a href="http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0/5243068#5243068">http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0/5243068#5243068</a> cites the relevant portions of the standard.<br>
<br>So I think you should remove the exception and verify the non-nullity of source and destination in any case.<br><br>Thanks for this useful check, it would have been very valuable to us :)<br>Matthieu.<br></div></div>