UNIVERSITY OF WISCONSIN
Computer Sciences Department
CS 639
Spring 2019
Barton Miller
Elisa Heymann
CS 639 - Exercise 3.1: Buffer Overflow
Due: Thursday, February 14 at the start of class

A. Warming Up

You will write code that overflows a buffer, where "overflow" means to write to memory outside the buffer, and where a "buffer" is an array of some fixed length. Using either pointers or array subscripts, write code that intentionally overflows a buffer. Try this experiment in C, plus two of the following scenarios: You will deliver the listing for your programs, and show the output. Explain (1) where/when the overflow happens and (2) how the program responded to the overflow.

B. Exploration Exercise 1

Work in C, with an array of long integers (long).

Experiment with buffer overflows when the array is allocated on the stack, heap, and when it is a global variable.

Overflow by 1, by 2, and then by 100, 1000 and 10,000. What behavior do you see in each case? Explain why you get each result.

Write a report that includes your code, and summarizes the experimentation carried out, the results, and your conclusions.

C. Exploration Exercise 2

Consider the following C program:
#include <stdio.h>
#include <stdlib.h>

int i;
long global[10];

int main (int argc, char *argv[]) {
    for (i=0; i<100; i++) {
        global[i] = 7;
        printf ("global[%d]\n", i);
    }
    printf ("Done\n");
    exit (0);
}

Compile and run this program on one of the Computer Science lab Linux machines. What output do you get from the program? Explain why you get this output?

Hand in Instructions

Hand in a printed copy of your programs and answers, and make sure you include your names in the document and in comments on each program.

Last modified: Sun Feb 10 14:52:08 CST 2019