Skip to content

Commit

Permalink
unistd: Increase maximum passwd/group buffer to 1MB
Browse files Browse the repository at this point in the history
We have one UNIX group that contains most of our users whose size is
about 20 kB, so `Group::from_name` is failing with ERANGE.

The discussion on PR nix-rust#864 suggests that 1 MB is a reasonable maximum -
it follows what FreeBSD's libc does. (glibc appears to have no maximum
on the _r function and will just double the buffer until malloc fails,
but that's not particularly Rusty.)
  • Loading branch information
geofft committed Mar 25, 2021
1 parent 6af11c1 commit aeabd36
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,7 @@ impl User {
libc::size_t,
*mut *mut libc::passwd) -> libc::c_int
{
let buflimit = 16384;
let buflimit = 1048576;
let bufsize = match sysconf(SysconfVar::GETPW_R_SIZE_MAX) {
Ok(Some(n)) => n as usize,
Ok(None) | Err(_) => buflimit as usize,
Expand Down Expand Up @@ -2762,7 +2762,7 @@ impl Group {
libc::size_t,
*mut *mut libc::group) -> libc::c_int
{
let buflimit = 16384;
let buflimit = 1048576;
let bufsize = match sysconf(SysconfVar::GETGR_R_SIZE_MAX) {
Ok(Some(n)) => n as usize,
Ok(None) | Err(_) => buflimit as usize,
Expand Down

0 comments on commit aeabd36

Please sign in to comment.