Buffer Overflow

Rewrite the program shown below so that it is no longer vulnerable to a buffer overflow.

int main (int argc, char *argv[]) {
    bool valid = false;
    char str1[8];
    char str2[8];

/* This is some function that assigns some string to str1 */

/* Read a string from standard input device (eg. keyboard) */

    if ( strncmp(str1, str2, 8) == 0 )

        valid = true;
    printf (“buffer1: str1(%s), str2(%s), valid(%d)n”, 
                                          str1, str2, valid);
Find Solution here

Leave a Reply

Your email address will not be published. Required fields are marked *