Skip to content

Commit

Permalink
Merge #1409
Browse files Browse the repository at this point in the history
1409: unistd: Increase maximum passwd/group buffer to 1MB r=asomers a=geofft

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 #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.)

Co-authored-by: Geoffrey Thomas <[email protected]>
  • Loading branch information
bors[bot] and geofft authored Apr 4, 2021
2 parents 6af11c1 + 2b6f77a commit c5d75b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2641,10 +2641,10 @@ 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,
Ok(None) | Err(_) => 16384,
};

let mut cbuf = Vec::with_capacity(bufsize);
Expand Down Expand Up @@ -2762,10 +2762,10 @@ 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,
Ok(None) | Err(_) => 16384,
};

let mut cbuf = Vec::with_capacity(bufsize);
Expand Down

0 comments on commit c5d75b8

Please sign in to comment.