secure_programming
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| secure_programming [2012/09/30 22:05] – created javapimp | secure_programming [2023/08/18 18:15] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| * Once the error condition is handled, the developer must "ramp up" again on where he left off on the " | * Once the error condition is handled, the developer must "ramp up" again on where he left off on the " | ||
| * It becomes very tempting to put off error handling to later, at which point it is easily neglected. | * It becomes very tempting to put off error handling to later, at which point it is easily neglected. | ||
| + | |||
| + | If you are going to put off error handling, don't just put in a " | ||
| + | <code cpp> | ||
| + | #define FAIL() | ||
| + | do { \ | ||
| + | fprintf(stderr, | ||
| + | abort(0); \ | ||
| + | } while(0) | ||
| + | </ | ||
| + | Then stub out your error checking: | ||
| + | <code cpp> | ||
| + | if(foo() == ERROR) | ||
| + | { | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Function returns the same value for success or failure ===== | ||
| + | |||
| ====== Buffer Overflows ====== | ====== Buffer Overflows ====== | ||
| Line 15: | Line 34: | ||
| ====== Memory Leaks ====== | ====== Memory Leaks ====== | ||
| + | ====== Memory Allocation ====== | ||
| + | <code cpp> | ||
| + | #ifdef CHECK_ALLOC | ||
| + | #define MALLOC bad_malloc | ||
| + | #else | ||
| + | #define MALLOC malloc | ||
| + | #endif | ||
| + | |||
| + | #define FAIL_COUNT = 3; | ||
| + | void* bad_malloc(size_t size) | ||
| + | { | ||
| + | | ||
| + | void* ret = NULL; | ||
| + | | ||
| + | ret = malloc(size); | ||
| + | else | ||
| + | fail = FAIL_COUNT; | ||
| + | | ||
| + | } | ||
| + | </ | ||
| ====== Heap Corruption ====== | ====== Heap Corruption ====== | ||
| + | |||
| + | ===== Electric Fence ===== | ||
| + | <code bash> | ||
| + | $ gcc -o foo foo.c -lefence | ||
| + | </ | ||
| ====== Race Conditions ====== | ====== Race Conditions ====== | ||
| + | |||
| + | ====== Code Coverage ====== | ||
| + | <code bash> | ||
| + | $ gcc -ftest-coverage -fprofile-arcs foo.c | ||
| + | $ gcov foo.c | ||
| + | </ | ||
| + | |||
| + | ====== Automated Tools ====== | ||
| + | <code bash> | ||
| + | $ splint -I/inc *.c | ||
| + | </ | ||
secure_programming.1349042718.txt.gz · Last modified: 2023/08/18 18:15 (external edit)