Skip to content

Commit e933e71

Browse files
lu-zeroAmanieu
authored andcommitted
std_detect: Unbreak auxv_from_file
Discovered on powerpc64 where it crashes since it has more entries.
1 parent b399168 commit e933e71

File tree

1 file changed

+6
-7
lines changed
  • crates/std_detect/src/detect/os/linux

1 file changed

+6
-7
lines changed

crates/std_detect/src/detect/os/linux/auxvec.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,12 @@ fn getauxval(key: usize) -> Result<usize, ()> {
189189
pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
190190
let file = super::read_file(file)?;
191191

192-
// See <https://github.com/torvalds/linux/blob/v3.19/include/uapi/linux/auxvec.h>.
192+
// See <https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/auxvec.h>.
193193
//
194-
// The auxiliary vector contains at most 32 (key,value) fields: from
195-
// `AT_EXECFN = 31` to `AT_NULL = 0`. That is, a buffer of
196-
// 2*32 `usize` elements is enough to read the whole vector.
197-
let mut buf = [0_usize; 64];
198-
let len = core::mem::size_of_val(&buf).max(file.len());
194+
// The auxiliary vector contains at most 34 (key,value) fields: from
195+
// `AT_MINSIGSTKSZ` to `AT_NULL`, but its number may increase.
196+
let len = file.len();
197+
let mut buf = alloc::vec![0_usize; 1 + len / core::mem::size_of::<usize>()];
199198
unsafe {
200199
core::ptr::copy_nonoverlapping(file.as_ptr(), buf.as_mut_ptr() as *mut u8, len);
201200
}
@@ -206,7 +205,7 @@ pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
206205
/// Tries to interpret the `buffer` as an auxiliary vector. If that fails, this
207206
/// function returns `Err`.
208207
#[cfg(feature = "std_detect_file_io")]
209-
fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
208+
fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
210209
// Targets with only AT_HWCAP:
211210
#[cfg(any(
212211
target_arch = "riscv32",

0 commit comments

Comments
 (0)