Vulnerability Development mailing list archives

Re: Secure coding in C (was Re: Administrivia #4883)


From: bk () LOCALHOST CA (Brian Kifiak)
Date: Sun, 16 Jan 2000 12:13:14 -0800


* Blue Boar (BlueBoar () THIEVCO COM) [01/15/00 22:12]:
Bennett Todd wrote:

        char *a = something();
        char *b = something_else();
        int len = strlen(a) + strlen(b);
        char *c = malloc(len + 1) || die("malloc");
        (void) strcat(strcpy(c, a), b);

If you have any reasonable idea what a maximum size for a or b might
be, then this could be better.  As it is, if I'm trying to DoS you
but sending huge strings, you've made it that much easier by doubling
the amount of RAM needed.  Since you're limiting yourself to MAXINT
anyway, you should check that against the sizes of a and b before
you malloc.

This is ludicrous.  There seems to be quite a bit of disagreement over the
proper way to handle this situation.  I find it hard to believe that there's
not an easy way to do this securely.  I'm troubled by all of the complex
solutions and lack of clarity that's getting spewed about.  Not everyone can
follow this discussion, and I doubt newer programmers would want to use
such a large magnitude of steps to do something quite simple.

Is there an easier way to do this? (I'm understanding what you're talking about
but I don't yet know enough about the language to come to a reasonable
solution.)

-bk


Current thread: