Main index | Section 7 | Options |
A good number of functions in the standard C library make it difficult or even impossible to prevent buffer overflows when used. These include fscanf(3), gets(3), getwd(3), realpath(3), scanf(3), sprintf(3), strcat(3), strcpy(3), vscanf(3), and vsprintf(3).
Many other functions that deal with strings can also open up a potential buffer overflow when not used carefully. For example, strncat(3) does not go out of its way to provide NUL character termination. Of course, the proper length must always be specified. Usage of strlcat(3) and strlcpy(3) ensure that strings are null terminated and of the specified length.
Functions that receive a string format must also be used carefully. It is possible for a string to contain additional format specifiers, which open up another possibility for a buffer overflow. Never pass a string with untrusted data without using ‘%s’. Always use the proper secure idiom:
function("%s", string);
There are mechanisms that provide a backstop for these problems at the library and compiler levels, however, there is no substitute for simply writing good code.
Often, jail(2) can be used to create a more complete and enclosed environment than chroot(2) can provide. A jail limits all processes inside that environment, including processes with superuser privileges.
Fine grained privileges, as described by POSIX.1e extensions, are currently a work in progress, and the focus of the TrustedBSD Project. More information can be found at http://www.TrustedBSD.org/.
SPROG (7) | June 3, 2001 |
Main index | Section 7 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.