Skip to content

bug: scope Rust FFI argument and result ownership #374

Description

@Andiveli

Problem

Rust-to-C JID arguments are converted with raw CString ownership even though Go only borrows them through C.GoString. Empty FFI query results can also expose a null pointer with zero length to Rust slice decoding.

Reproduction or motivating example

  1. Call a bridge query or outbound send that passes a JID from Rust to Go.
  2. Repeat the operation and observe that the raw CString allocation has no matching release.
  3. Request contacts when Go returns an empty {nil, 0} result.

Expected behavior

Borrowed FFI arguments remain owned by Rust for the duration of the call, and empty results decode safely without constructing a slice from a null pointer.

Actual behavior

JID conversion transfers ownership without a matching free, and empty result decoding does not explicitly guard the null/zero case.

Relevant evidence

Affected code is in whatsrust/src/models.rs, whatsrust/src/queries.rs, and whatsrust/src/message_send.rs.

Acceptance criteria

  • JID C strings have scoped Rust ownership across every FFI call.
  • The public ABI remains unchanged.
  • Empty contact results decode as an empty collection safely.
  • Focused Rust tests cover ownership and empty-result behavior.

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

    bugSomething isn't workingstatus:approvedIssue approved for implementation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions