Skip to content

Commit

Permalink
major update to allow 2 sanitizers to be simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-taylor committed May 17, 2019
1 parent d605a5c commit b4a4b4c
Show file tree
Hide file tree
Showing 424 changed files with 2,444 additions and 1,579 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ tmp*

# don't accidentally add random test files to repo
/*.c
!/main_wrapper.c
!/dcc_*.c
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PACKAGED_SOURCE = start_gdb.py drive_gdb.py watch_valgrind.py colors.py main_wrapper.c
PACKAGED_SOURCE = start_gdb.py drive_gdb.py watch_valgrind.py colors.py dcc_main.c dcc_dual_sanitizers.c dcc_util.c
SOURCE = __main__.py compile.py explain_compiler_output.py compiler_explanations.py help_cs50.py $(PACKAGED_SOURCE)
PACKAGE_NAME=src

Expand All @@ -23,7 +23,7 @@ tests: dcc
tests/do_tests.sh ./dcc

tests_all_clang_versions: dcc
set -x ; for compiler in /usr/bin/clang-[1-24-9]* ; do tests/do_tests.sh ./dcc $$compiler; done
for compiler in /usr/bin/clang-[1-24-9]* ; do echo $$compiler;tests/do_tests.sh ./dcc $$compiler; echo; done

debian: dcc
rm -rf debian
Expand Down
38 changes: 10 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ For example:
a = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}
i = 10

dcc can alternatively embed code to detect use of uninitialized variables
dcc also embeds code to detect use of uninitialized variables
and print a message a novice programmer can hopefully understand. For example:

$ dcc --memory uninitialized.c
$ dcc uninitialized.c
$ ./a.out
uninitialized.c:6 runtime error uninitialized variable used

Expand All @@ -60,41 +60,22 @@ and print a message a novice programmer can hopefully understand. For example:
a[43] = <uninitialized value>
a[argc] = <uninitialized value>

# Valgrind
Uninitialized variables are detected by running valgrind simultaneously as a separate process.

dcc can alternatively embed code in the binary to run valgrind instead of the binary:

$ dcc --valgrind buffer_overflow.c
$ ./a.out
Runtime error: uninitialized variable accessed.

Execution stopped here in main() in uninitialized-array-element.c at line 6:

int a[1000];
a[42] = 42;
--> if (a[argc]) {
a[43] = 43;
}

Values when execution stopped:

argc = 1
a[42] = 42
a[43] = <uninitialized value>
a[argc] = <uninitialized value>

valgrind is slower but more comprehensive in its detection of uninitialized variables than MemorySanitizer.
The synchronisation of the 2 processes is only effective for the standard C library (signal.h and threads.h excepted).
which should include almost all typical programs writen by novice programmers.
f synchronisation is lost the 2nd process should terminate silently.

If libraries other the standard C library are used, uninitialized variables does not occur.

# Leak checking

dcc can also embed code to check for memory-leaks:

$ dcc --valgrind --leak-check leak.c
$ dcc --leak-check leak.c
$ ./a.out
Error: free not called for memory allocated with malloc in function main in leak.c at line 3.

This option can not also be used for (the default) Address sanitizer but error are not intercepted and may be cryptic
for novice programmers.

# Local Variable Use After Function Return Detection

Expand Down Expand Up @@ -149,6 +130,7 @@ valgrind also usually detect this type of error, e.g.:
sudo curl https://github.com/COMP1511UNSW/dcc/releases/download/1.11/dc -o /usr/bin/dcc
sudo chmod o+rx /usr/bin/dcc


# Run-time Error Handling Implementation

* dcc by default enables clang's AddressSanitizer (`-fsanitize=address`) and UndefinedBehaviorSanitizer (`-fsanitize=undefined`) extensions.
Expand Down
Loading

0 comments on commit b4a4b4c

Please sign in to comment.