mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 17:31:14 -03:00
Do not mmap with len 0
`mmap` should fail when the length argument is 0. Checking this in advance allows returning early, without performing unnecessary syscalls. This also fixes an issue observed on FreeBSD 13.2 where `mmap` does not always fail when the length is 0, resulting in the `assert!(len > 0)` in `MmapRegion::new` failing. https://github.com/fish-shell/fish-shell/issues/11595
This commit is contained in:
@@ -128,6 +128,12 @@ pub fn create(mut history_file: &File) -> std::io::Result<Self> {
|
||||
))
|
||||
}
|
||||
};
|
||||
if len == 0 {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"History file is empty. Cannot create memory mapping with length 0.",
|
||||
));
|
||||
}
|
||||
let map_anon = |mut file: &File, len: usize| -> std::io::Result<MmapRegion> {
|
||||
let mut region = MmapRegion::map_anon(len)?;
|
||||
// If we mapped anonymous memory, we have to read from the file.
|
||||
|
||||
Reference in New Issue
Block a user