Check all of your arguments. Arguments that you pass to Unix system functions. Do bounds checking on every variable. Data should be bounded, and verified for syntactic correctness integrity, and origin if possible. Don't use routines that fail to check buffer boundaries when manipulating strings of arbitrary length.
Bounds check all data manipulation.
Check all return codes from system calls. The Unix operating system has almost every single system call return a return code. Do not always assume it will succeed. Don't have your program depend on Unix environment. Erase what you don't need first, get what you want, and kill the remainder.