Skip to content

conf_mut() accessors allow aliasing violations and should be marked as as unsafe #284

Description

@bavshin-f5

main_conf_mut() returns &'static mut Self::MainConf from only an &impl CoreModuleConfExt. This allows safe code to obtain multiple mutable references to the same underlying NGINX config slot (e.g., calling main_conf_mut() twice), which violates Rust aliasing rules and can lead to UB. Consider making the accessor unsafe, requiring a unique borrow (&mut impl ...), or returning a raw/NonNull pointer instead of &mut.

    ///
    /// # Safety
    /// The caller must guarantee exclusive access to this module's configuration slot for the
    /// full lifetime of the returned reference. Calling this multiple times for the same
    /// underlying slot, or while any shared or mutable references to that slot exist, violates
    /// Rust's aliasing rules and results in undefined behavior.
    unsafe fn main_conf_mut(o: &impl CoreModuleConfExt) -> Option<&'static mut Self::MainConf> {

Originally posted by @Copilot in #283 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions