Interesting C thingy
Dan.Osterrath at gmx.de
Mon Aug 9 11:13:27 PDT 2004
Am Montag, 9. August 2004 20:09 schrieb Miguel Bazdresch:
> * Jason Gurtz <jason at tommyk.com> [2004-08-09 17:55]:
> > On 8/9/2004 12:56, Miguel Bazdresch wrote:
> > > printf("%c\n",9[str]); only prints the newline, i expected it to
> > > segfault :)
> > Hmm, well maybe, maybe not. Clearly it's beyond the bounds of the array
> > which is leagl. But you don't know what you're going to get. Maybe
> > you were lucky and got \0?
> Does that mean reading unallocated memory is fine? What about kernel
> memory, or the memory where some guy's (logged to the same machine) gpg
> key is stored?
unallocated != unmapped
When you access memory that is not allocated by you but still in a memory page
you are allowed to access everything is fine. Accessing a memory page you are
not allowed to causes a segfault.
a is memory allocated by you
b and c is unallocated memory
 is the border for a page
the first page belongs to your process
the second page belongs to some other process or the kernel
reading in a is fine
reading in b might be fine as the data can have random content
reading in c causes a signal 11
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
More information about the lfs-chat