Memory Safety Lab

In this lab, you will diagnose and fix memory errors in a simple program. To do this, we will be using a debugging tool intended to help identify memory errors. This tool is built-in into the C compiler you can use after running module load gcc on the lab machines. It is also usually included in recent versions of gcc or clang.

Your Task

  1. Download asanlab.tar and extract it. This contains an example broken implementation of a circular doubly-linked list library and a test program for it.

  2. If you are on a department machine, run module load gcc before running any of the commands below, to use aa sufficiently recent version of GCC.

  3. Run make in the root directory the given program.

  4. Run make test to run our test program under a memory error detector called AddressSanitizer.

  5. Modify ll.c so make test reports no errors. (This includes errors from the test program itself and from AddressSanitizer.)

  6. Submit your fixed ll.c to kytos. You may work with other students in your lab, but each student must submit an ll.c.

Troubleshooting

  1. If you run into trouble with not getting line numbers in stack traces, try doing the lab on a department machine, such by SSH’ing, and running module load gcc, then make clean followed by make to force everything to be recompiled and linked on those machines.

  2. If you get an error like /usr/bin/ld: cannot find /usr/lib64/libasan.so.0.0.0, and you’re logged into portal or nxfront, run module load gcc, then make clean, then try again.

Hints

Files in the Archive

Understanding AddressSanitizer

The Shadow Memory

Interpreting Output

Invalid reads and writes

Memory leaks

General debugging advice