Out-of-bounds pointers
Conor P. Cahill
cpcahil at virtech.UUCP
Wed Oct 11 21:50:30 AEST 1989
In article <238 at bbxsda.UUCP>, scott at 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 |
+-----------------------------------------------------------------------+
More information about the Comp.std.c
mailing list