diff options
author | Steven Danna <steve@chef.io> | 2020-04-06 12:54:59 +0000 |
---|---|---|
committer | Steven Danna <steve@chef.io> | 2020-04-06 14:27:18 +0000 |
commit | 3c2107bdc221a90b02d3f7118dd96f3496762cd0 (patch) | |
tree | dfc5ca5786438e85ca36d654fe2fc3b37cfd07db /src/unistd.rs | |
parent | 627dff904688ad223558a50bd499207e940e47cd (diff) | |
download | nix-3c2107bdc221a90b02d3f7118dd96f3496762cd0.zip |
unistd: avoid infinite loop caused by reserve_double_buffer_size
Functions such as Group::from_anything use reserve_double_buffer_size
in a loop, expecting it to return ERANGE if the passed limit is
reached.
However, the returned vector is passed as pointer to a libc function
that writes data into memory and doesn't update the length of the
Vec. Because of this, the previous code would never return ERANGE and
the calling loops would never exit if they hit a case where the
required buffer was larger than the maximum buffer.
This fixes the problem by checking the capacity rather than the
length.
Signed-off-by: Steven Danna <steve@chef.io>
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 64873635..f6efb364 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -507,13 +507,13 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> { } /// Creates new fifo special file (named pipe) with path `path` and access rights `mode`. -/// +/// /// If `dirfd` has a value, then `path` is relative to directory associated with the file descriptor. -/// -/// If `dirfd` is `None`, then `path` is relative to the current working directory. -/// +/// +/// If `dirfd` is `None`, then `path` is relative to the current working directory. +/// /// # References -/// +/// /// [mkfifoat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifoat.html). // mkfifoat is not implemented in OSX or android #[inline] @@ -559,7 +559,7 @@ pub fn symlinkat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>( fn reserve_double_buffer_size<T>(buf: &mut Vec<T>, limit: usize) -> Result<()> { use std::cmp::min; - if buf.len() >= limit { + if buf.capacity() >= limit { return Err(Error::Sys(Errno::ERANGE)) } |