fix: Require non-null pointer in StorePath

Fixes https://github.com/nixops4/nixops4/issues/65,
possible undefined behavior.

This doesn't make the code nice wrt *const/*mut distinction, but
since we're not mutating it, this should be fine.

(cherry picked from commit 75d448aad923a5f835f0562400e223df43103ea4)
This commit is contained in:
Robert Hensing 2024-12-16 14:11:17 +01:00
parent 28deb20a2b
commit 6193575d1e
2 changed files with 21 additions and 6 deletions

View file

@ -403,6 +403,11 @@ impl EvalState {
let mut paths = Vec::with_capacity(n as usize);
for i in 0..n {
let path = raw::realised_string_get_store_path(rs, i);
let path = NonNull::new(path as *mut raw::StorePath).ok_or_else(|| {
anyhow::format_err!(
"nix_realised_string_get_store_path returned a null pointer"
)
})?;
paths.push(StorePath::new_raw_clone(path));
}
paths