| ... | @@ -720,11 +720,25 @@ pub fn getegid() gid_t { | ... | @@ -720,11 +720,25 @@ pub fn getegid() gid_t { |
| 720 | } | 720 | } |
| 721 | | 721 | |
| 722 | pub fn seteuid(euid: uid_t) usize { | 722 | pub fn seteuid(euid: uid_t) usize { |
| 723 | return setresuid(std.math.maxInt(uid_t), euid); | 723 | // We use setresuid here instead of setreuid to ensure that the saved uid |
| | 724 | // is not changed. This is what musl and recent glibc versions do as well. |
| | 725 | // |
| | 726 | // The setresuid(2) man page says that if -1 is passed the corresponding |
| | 727 | // id will not be changed. Since uid_t is unsigned, this wraps around to the |
| | 728 | // max value in C. |
| | 729 | comptime assert(@typeInfo(uid_t) == .Int and !@typeInfo(uid_t).Int.is_signed); |
| | 730 | return setresuid(std.math.maxInt(uid_t), euid, std.math.maxInt(uid_t)); |
| 724 | } | 731 | } |
| 725 | | 732 | |
| 726 | pub fn setegid(egid: gid_t) usize { | 733 | pub fn setegid(egid: gid_t) usize { |
| 727 | return setregid(std.math.maxInt(gid_t), egid); | 734 | // We use setresgid here instead of setregid to ensure that the saved uid |
| | 735 | // is not changed. This is what musl and recent glibc versions do as well. |
| | 736 | // |
| | 737 | // The setresgid(2) man page says that if -1 is passed the corresponding |
| | 738 | // id will not be changed. Since gid_t is unsigned, this wraps around to the |
| | 739 | // max value in C. |
| | 740 | comptime assert(@typeInfo(uid_t) == .Int and !@typeInfo(uid_t).Int.is_signed); |
| | 741 | return setresgid(std.math.maxInt(gid_t), egid, std.math.maxInt(gid_t)); |
| 728 | } | 742 | } |
| 729 | | 743 | |
| 730 | pub fn getresuid(ruid: *uid_t, euid: *uid_t, suid: *uid_t) usize { | 744 | pub fn getresuid(ruid: *uid_t, euid: *uid_t, suid: *uid_t) usize { |