|
|||||||||||
|
Re: safe strcpy()?
From: Michal Zalewski <lcamtuf(at)coredump.cx>
Date: Tue Jan 28 2003 - 04:14:37 EST
> This lef me to go back to my C textbooks (which I hadn't liiked in
Not really. C itself does not provide any built-in mechanism for passing sizes of buffers or other objects. Sizeof() is merely replaced with the storage size of whatever you passed to it during the compilation, and is not a runtime mechanism for determining the size of an object you point to. > I'm not interested in manual manipulation of code, or suggestions on
No. C is a fairly low-level language. There are some versions of C that generate code with range checking and such, but it's not very common (and not always as effective as in other languages). You think what made C co popular?;-) If you write your code in range checked, strong typed language, you get some strange errors all the time... if you write it in C, it runs, *maybe* sometimes behaves strangely because some variable gets overwritten, but hey, good enough to release ;-) You just call register_buf() whenever you create an array, a structure or such. Its address, length and element size would be stored, so that you can query for a buffer at any time, and perhaps decide, based on element size, if its suitable for the operation you are about to perform (so that when you have a number of buffers inside an array, and you only added the array to implement index range checking, but forgot to add single buffers, your code would not overwrite other elements when modifying one, but rather bail out because of element size mismatch). The approach is not perfect, but can be quite helpful.
--
------------------------- bash$ :(){ :|:&};: --
Michal Zalewski * [
http://lcamtuf.coredump.cx]
Did you know that clones never use mirrors?
--------------------------- 2003-01-28 00:41 --
Received on Tue Jan 28 12:13:55 2003This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:45 EDT |
||||||||||
|
|||||||||||