Re: Stack growth direction to thwart buffer overflow attacks
From: Isaac To (kkto_at_csis.hku.hk)
Date: 08/20/03
- Next message: Casper H.S. ***: "Re: Stack growth direction to thwart buffer overflow attacks"
- Previous message: Douglas Siebert: "Re: Stack growth direction to thwart buffer overflow attacks"
- In reply to: Frank Cusack: "Re: Stack growth direction to thwart buffer overflow attacks"
- Next in thread: Casper H.S. ***: "Re: Stack growth direction to thwart buffer overflow attacks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 21 Aug 2003 00:11:38 +0800
>>>>> "Frank" == Frank Cusack <fcusack@fcusack.com> writes:
Frank> ahh. How confusing. I let myself get carried away once I
Frank> thought I saw a problem. In fact, I'm sure I've argued this
Frank> incorrectly in the distant past as well.
Frank> I stand by my point; it's hard to get this right, and secondly,
Frank> strn* are not the best design. Why does strncpy() not
Frank> null-terminate while strncat() does? blah. C lends itself to
Frank> these kinds of errors.
I don't have much problem with the "confusing" problem with C string
operations. I think C-style strings are pretty low-level data
representation with not much abstraction per-se, so I won't judge it in the
same way as, say, a C++ std::string.
On the other hand, I do find a lot of C operations poorly thought-out about
how to provide the most useful interface, which is something I really don't
like. The strcat/strncat gives a very good example. It's return value is
the input char pointer. What the hell that anybody would think want
something I already had? Why not return the pointer pointing to the end of
the concatenated string, which must be known by the operation anyway? To do
so in a separate round it requires rescanning the string using strlen(),
which is not at all efficient. Think about something like this...
char x[1024] = "";
strcat(x, "abc ");
strcat(x, "def ");
strcat(x, "ghi ");
...
it concatenate a sequence of strings, but this uses n^2 time. The best that
the current interface can do is to reduce it to scanning the string twice,
by finding the end of string everytime using strlen. If strcat just returns
the end-of-string, one would easily write
char x[1024] = "";
char *curr = strcat(x, "abc ");
curr = strcat(curr, "def ");
curr = strcat(curr, "ghi ");
...
which does exactly the same thing, but in linear time, scanning each string
exactly once.
Regards,
Isaac.
- Next message: Casper H.S. ***: "Re: Stack growth direction to thwart buffer overflow attacks"
- Previous message: Douglas Siebert: "Re: Stack growth direction to thwart buffer overflow attacks"
- In reply to: Frank Cusack: "Re: Stack growth direction to thwart buffer overflow attacks"
- Next in thread: Casper H.S. ***: "Re: Stack growth direction to thwart buffer overflow attacks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]