Re: why the usage of gets() is dangerous.
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Sat, 24 Nov 2007 22:25:47 GMT
CBFalconer wrote:
Flash Gordon wrote:....
So provide such an impossibility then you will have proved your
position.
So here is another. Imagine a routine to upshift a string. One
routine receives a char, and answere with 'this is lower case'. Another receives a char, and answers by replacing it with the upper
case equivalent. Both are passed pointers.
Assuming the original data is a string, the calling routine will
pass something like:
p = &(s[3]); or p = s + 3; (p is parameter)
For the reading routine, there is no harm in allowing reads from (p
- n), where n can be 0 through 3. For the writing routine, this is
not allowable. How do we separate the actions?
Distinguishing readable from writable memory is what 'const' is for. Fat pointers are for bounds checking.
You don't indicate whether s is a pointer or an array. For simplicity, I'll assume that it's an array of N chars. Then when s decays into a pointer, that pointer's limits are set to s and s+N. When s+3 is evaluated, it inherits those same limits, and they are retained when that pointer value is stored in p. As a result, any attempt to calculate p+i for i<-3 or i>N-3 will trigger a failure mechanism. any attempt to evaluate p[i] for i<-3 or i >= N-3 will trigger a failure mechanism, and that's true whether the access is for read or write.
.
- References:
- why the usage of gets() is dangerous.
- From: jayapal
- Re: why the usage of gets() is dangerous.
- From: Paul Hsieh
- Re: why the usage of gets() is dangerous.
- From: Malcolm McLean
- Re: why the usage of gets() is dangerous.
- From: Richard Heathfield
- Re: why the usage of gets() is dangerous.
- From: Malcolm McLean
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- Re: why the usage of gets() is dangerous.
- From: Keith Thompson
- Re: why the usage of gets() is dangerous.
- From: Tor Rustad
- Re: why the usage of gets() is dangerous.
- From: Richard Bos
- Re: why the usage of gets() is dangerous.
- From: Tor Rustad
- Re: why the usage of gets() is dangerous.
- From: Richard Bos
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- Re: why the usage of gets() is dangerous.
- From: Flash Gordon
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- Re: why the usage of gets() is dangerous.
- From: Flash Gordon
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- why the usage of gets() is dangerous.
- Prev by Date: Re: how can I puts a char array reserve by recursion algoritym?
- Next by Date: Re: why the usage of gets() is dangerous.
- Previous by thread: Re: why the usage of gets() is dangerous.
- Next by thread: Re: why the usage of gets() is dangerous.
- Index(es):
Relevant Pages
|