B
Bartc
Eric Sosman said:Bartc said:The gets() implementation which gets a non-NULL value from alloc_size can
then test against the limit (I had in mind the address of the end of the
allocated block), and prevent buffer overflows.
You're kidding, right?
struct foo {
char buffer[100];
void (*method)(void);
};
struct foo *p = malloc(sizeof *p);
if (p != NULL) {
p->method = my_function;
gets(p->buffer);
p->method();
}
Even if gets() discovers that the size allocated to the pointer it
got is 104, say, how will it know to stop at 100?
That's true. Then the safe uses of gets() would be even more restricted.
But it also reduces the usefulness of the entire idea of obtaining size and
block limits of allocated pointers. If someone just allocates a single large
malloc block then suballocates from that, then knowing the limits of that
one block is not too helpful.
Back to the drawing board then.