Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!wugate!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.std.c Subject: Re: Out-of-bounds pointers Message-ID: <1258@virtech.UUCP> Date: 11 Oct 89 11:50:30 GMT References: <1009@mtxinu.UUCP> <12570028@hpclwjm.HP.COM> <868@crdos1.crd.ge.COM> <238@bbxsda.UUCP> Organization: Virtual Technologies Inc Lines: 42 In article <238@bbxsda.UUCP>, scott@bbxsda.UUCP (Scott Amspoker) writes: > It is customary for subroutines (such as free()) to save registers > on the stack and restore their values upon return. NOTHING IS > BEING PASSED BACK TO THE CALLER! The subroutine is merely > restoring a register to its original value. The value of the > pointer is being pushed as an argument to the subroutine. That > value ultimately is discarded. However, the register containing > the pointer may also be pushed to preserve its value. Please check > some assembly code output of practically any C compiler of a function > that uses register variables. Normally the subroutine only saves and restores register variables that it uses within the subroutine. The person writing the compiler and free() for a system wherein free() gives the space back to the system and a program would blow up if an invalid address is loaded into a register could do one of the following: 1. write free() so that it does not make use of any pointer registers that would be used for a "register char *p". so that it would not have to save/restore said register. 2. free() could examine the pointer registers and invalidate any of them that would now point to nonsense (before it makes them point to nonsense. This could be done automatically by the system, since it knows what the adress vars are and what the users address space is. 3. disreguard the "register" on "register char *p" or some sub-set thereof (like disreguard it if the pointer is passed out of the subroutine). These are just three mechanisms that I thought of off the top of my head and I ain't no compiler writer. So I would conclude that your example would not be a problem (any compiler that had you're behavior would be useless, so this discussion is really a waste of bandwidth). -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+