Skip to content

get_payload has undefined behaviour in release mode #23

Description

@RazorBest

I tried compiling an example using this create, that uses Message::get_payload. If compiled in debug mode, the program works as expected. However, when compiled in release mode, after calling Message::get_payload, if we try to print the payload, it generates a segfault.

After some debugging, I came to the conclusion thatMessage::get_payload compiles to a machine code that returns the NULL pointer. This comes from a wrongly specified behavior in the unsafe context. The function calls nfq_get_payload(self.nfad, &c_ptr), which actually modifies the reference, since nfq_get_payload receives a **void. The given reference should be mutable.

To fix this, the extern definition of nfq_get_payload in message.rs should be changed from this:

fn nfq_get_payload (nfad: NfqueueData, data: &*mut libc::c_void) -> libc::c_int;

To this:

fn nfq_get_payload (nfad: NfqueueData, data: &mut *mut libc::c_void) -> libc::c_int;

Environment

  • cargo 1.92.0
  • rustc 1.92.0

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions