Updated: April 19, 2023 |
Specify the lowest acceptable file descriptor
#include <fcntl.h> int set_lowest_fd( int fd );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The set_lowest_fd() function sets the lowest file descriptor number that will be returned by open(), pipe(), and other functions that return file descriptors. A process with the setuid/setgid file permission bit set can use this function at the begining of main() to ensure that it never unexpectedly gets back a file descriptor equal to 0, 1, or 2, which malicious programmers sometimes cause to happen by closing stdin, stdout, or stderr before spawning the process.
The previous lowest number (0 for the first time it's called).
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | No |