-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding function check_fds to new file fd.c. The function check_fds should be called in every setuid/setgid program. Co-developed-by: Alejandro Colomar <[email protected]>
- Loading branch information
1 parent
b76fc29
commit d2f2c18
Showing
11 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-FileCopyrightText: 2024, Skyler Ferrante <[email protected]> | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
/** | ||
* To protect against file descriptor omission attacks, we open the std file | ||
* descriptors with /dev/null if they are not already open. Code is based on | ||
* fix_fds from sudo.c. | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include "prototypes.h" | ||
|
||
static void check_fd(int fd); | ||
|
||
void | ||
check_fds(void) | ||
{ | ||
/** | ||
* Make sure stdin, stdout, stderr are open | ||
* If they are closed, set them to /dev/null | ||
*/ | ||
check_fd(STDIN_FILENO); | ||
check_fd(STDOUT_FILENO); | ||
check_fd(STDERR_FILENO); | ||
} | ||
|
||
static void | ||
check_fd(int fd) | ||
{ | ||
int devnull; | ||
|
||
if (fcntl(fd, F_GETFL, 0) != -1) | ||
return; | ||
|
||
devnull = open("/dev/null", O_RDWR); | ||
if (devnull != fd) | ||
abort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters