Vulnerability Development mailing list archives

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


From: BlueBoar () THIEVCO COM (Blue Boar)
Date: Sat, 15 Jan 2000 22:03:28 -0800


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.

OTOH, since you mentioned this is a mail app... if those variables
represent the body of the message, you have no real choice.

                                        BB


Current thread: