This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: US-CERT Vulnerability Note VU#162289
- From: Paul Schlie <schlie at comcast dot net>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 24 Apr 2008 20:39:31 -0400
- Subject: Re: US-CERT Vulnerability Note VU#162289
Mark Mitchell wrote:
> ...
>
> And:
>
>> Addition or subtraction of a pointer into, or just beyond, an array object
>> and an integer type produces a result that does not point into, or just
>> beyond, the same array object (6.5.6).
>>
>> is undefined behavior.
So then unless the compiler can determine that all pointers passed to foo,
for example below, represent a pointer to some Nth element of some array
from which not more than N will be effectively subtracted, the optimization
(if it can be called that) can not be performed, as a sum of a pointer and
an arbitrary integer may be validly be less than said pointer, as follows:
foo(char* p){
if (p+(char*)-1 < p)
<something> }
char a[] {0,1,2,3};
foo(a+2);
I believe.