secure set-id shell script support

This commit is contained in:
Jōshin 2023-12-17 13:38:58 +00:00
parent 3c7ad0eab2
commit 88fbcebb08
No known key found for this signature in database

View file

@ -37,6 +37,7 @@
#define KERN_PROC 14
#define KERN_PROC_PATHNAME_FREEBSD 12
#define KERN_PROC_PATHNAME_NETBSD 5
#define DEV_FD "/dev/fd/"
static struct {
atomic_uint once;
@ -114,6 +115,15 @@ static inline void InitProgramExecutableNameImpl(void) {
return;
}
if (issetugid() && __program_executable_name &&
(IsNetbsd() || IsOpenbsd() || IsXnu()) &&
!strncmp(DEV_FD, __program_executable_name, sizeof(DEV_FD) - 1) &&
isdigit(__program_executable_name[sizeof(DEV_FD)]) &&
!strchr(__program_executable_name + sizeof(DEV_FD) + 1, '/')) {
/* loader passed us a secure path */
return;
}
b = g_prog.u.buf;
n = sizeof(g_prog.u.buf) - 1;
if (IsFreebsd() || IsNetbsd()) {