Skip to main content

CStrArray

Struct CStrArray 

Source
pub struct CStrArray<'a> { /* private fields */ }
Expand description

Tableau de pointeurs C terminé par NULL, pour le marshalling d’argv / envp vers execve(2) / execveat(2).

Ces syscalls attendent un argument de type char *const argv[] : une suite de pointeurs vers des chaînes C terminée par un pointeur NULL. Ce type matérialise cette frontière de marshalling, qui est fuzzée (fuzz/fuzz_targets/fuzz_exec_argv.rs) : construction depuis une liste arbitraire (vide, longue), terminaison NULL toujours présente, ordre préservé.

Rejet des NUL embarqués — par construction. Un argument C ne peut pas contenir d’octet NUL (il y serait interprété comme terminateur). L’entrée étant une tranche de CStr — type qui garantit l’absence de NUL interne — l’invariant est assuré en amont, là où l’appelant construit ses &CStr (typiquement via CStr::from_bytes_with_nul ou CString::new, qui rejettent proprement un NUL embarqué). Aucune revalidation n’est donc nécessaire ici (Principe 4 : « parse, don’t validate »).

Allocation. La construction alloue un Vec de items.len() + 1 pointeurs : c’est l’exception d’allocation documentée d’ADR-021 §4 (buffer dynamique intrinsèque — sa taille dépend du nombre d’arguments, inconnu à la compilation). Les chaînes elles-mêmes ne sont pas copiées : les pointeurs empruntent les CStr fournis (d’où la durée de vie 'a).

Implementations§

Source§

impl<'a> CStrArray<'a>

Source

pub fn new(items: &'a [&'a CStr]) -> Self

Construit le tableau NULL-terminé à partir de items.

Une tranche vide produit un tableau ne contenant que le NULL final (argv = { NULL }, soit argc == 0) — accepté par le kernel.

Source

pub fn len(&self) -> usize

Nombre d’arguments (hors terminateur NULL).

Source

pub fn is_empty(&self) -> bool

Vrai si la liste est vide (le tableau ne contient que le NULL final).

Auto Trait Implementations§

§

impl<'a> Freeze for CStrArray<'a>

§

impl<'a> RefUnwindSafe for CStrArray<'a>

§

impl<'a> !Send for CStrArray<'a>

§

impl<'a> !Sync for CStrArray<'a>

§

impl<'a> Unpin for CStrArray<'a>

§

impl<'a> UnsafeUnpin for CStrArray<'a>

§

impl<'a> UnwindSafe for CStrArray<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.