UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Buffer overflows

Vulnerable to buffer overflow

This example will cause problems if the user enters more than fourteen characters. (Why 14 and not 15?)

#include <stdio.h>
int main()
{
   char buff[15] = {0};  
   printf("enter your name: ");
   scanf("%s", buff);
}
Using gets( ) introduces the same vulnerability.

Safe from buffer overflow

This example is safe since fgets( ) will return at most 14 characters plus NULL.

#include <stdio.h>
int main()
{
   char buff[15] = {0};

   fgets(buff, sizeof(buff), stdin); 
}

Ok, So how does a worm grab control of your computer?

  1. If a cracker knows the code of the program he's attacking (e.g., Unix finger)
  2. And it does unsafe string operations
  3. He feeds it an overly long string
  4. part of which will overwrite parts of the program
  5. with characters that will be subsequently interpreted as code
  6. that, when executed, will do what he wants.


CSEE | 201 | 201 F'06 | lectures | news | help

Last Modified - Tuesday, 22-Aug-2006 07:14:08 EDT