*BSD News Article 26264


Return to BSD News archive

Newsgroups: comp.os.386bsd.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!bunyip.cc.uq.oz.au!harbinger.cc.monash.edu.au!yeshua.marcam.com!news.kei.com!eff!news.umbc.edu!europa.eng.gtefsd.com!howland.reston.ans.net!pipex!uknet!festival!edcogsci!richard
From: richard@cogsci.ed.ac.uk (Richard Tobin)
Subject: Re: [Q] *(int*)NULL Ok??
Message-ID: <CJu19y.Kvq@cogsci.ed.ac.uk>
Organization: HCRC, University of Edinburgh
References: <9401181422.AA18524@moose.usmcs.maine.edu>
Date: Tue, 18 Jan 1994 15:49:10 GMT
Lines: 31

In article <9401181422.AA18524@moose.usmcs.maine.edu> swanton@moose.usmcs.maine.edu (George P. Swanton) writes:
>The following program also runs without complaint on both this and my 
>NetBSD-0.8 system (both nobrand 486dx)
>
>main() { 
>  int i;
>  i = *(int*)0;
>}

In NetBSD 0.8, location zero is at the beginning of the text segment.  It
is therefore readable...

>  *(int*)0 = 1;
>
>causes a fault.

... but read-only.

In NetBSD 0.9, the first page is unmapped, so any reference to location
zero causes an error.

Assuming that one could read location zero (and get zero back) was
common in VAX BSD code.  Various BSD derivatives (eg SunOS) unmapped
page zero, and many programs had to be fixed.  A common example is
passing 0 as an argument to str* functions.

-- Richard
-- 
Richard Tobin, HCRC, Edinburgh University                 R.Tobin@ed.ac.uk

"We demand guaranteed rigidly defined areas of doubt and uncertainty" - HHGTTG