Subject: Re: strlen on a NULL
From: [email-masked] (Ron G. Minnich)

14 May 1998 00:02:42 -0700
Message-ID: <Pine.SUN.3.91.980513093003.7451F-100000.cygnus.gnu-win32@terra>
References: <H00000b00005bfcb@MHS>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
To: [email-masked]
Cc: [email-masked], [email-masked]

On Tue, 12 May 1998 [email-masked] wrote:

> > If I do a strlen on a NULL pointer I get a coredump.
> > I have the same code running on a few *other* Unix machines with
> > exhibiting this behaviour.
> > OK, so I could tidy it up, but I wondered is this an oversight or the
> > correct behaviour?
> 
> I just observed the same problem.
> The differnce lies in where the core is located. A UNIX core starts from
> ZERO, and thus you are allowed to read from a NULL pointer on UNIX, as
> You read from your code.
> 
> On NT your process may lie anywhere, but never in ZERO, Thus you are not
> permitted to read from adress NULL. (You are not allowed to snoop around
> in the interrupt vetors!)
> 
> So this is the explanation!
>   
>   Kjeld

This is quite wrong for most unixes. 

cat test.c
main()
{
  char *c = (char *) 0;
  char d;

  d = *c;
}

bash$ cc test.c
bash$ ./a.out
Segmentation fault (core dumped)
on FreeBSD, linux, solaris, sunos ...

Anyway, check the kernel source, and see the part where they make page
0 unreadable and unwriteable. Stupid exceptions: some SvR4 
implementations, and of course stupid old AIX.

ron
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".