rustls / rustls/rustls-ffi

Review documented lifetime requirements for `&mut` vs `*mut` rules

Open
#309 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
170
Forks
43
Avg merge
1d 1h
Merged PRs (30d)
10

Description

(Copied from https://github.com/rustls/rustls-ffi/pull/291#issuecomment-1481711750)

We arrange for (non-Rust) callers of our function to uphold the safety guarantees by asking them to uphold a few properties:

  • We only hand out pointers to our structs that follow the rules above (aligned, initialized, etc).
  • We document the lifetime requirements of those pointers.
  • We provide *const pointers for things that may have aliases.
  • We expect callers to never cast between types or cast away const.
  • We provide *mut pointers for things that may be mutated. This is actually an area we should tighten up. The rules for what you can do with a *mut pointer are very slightly looser than the rules for what you can do with an &mut reference. For instance, the rules are triggered on dereference of raw pointers, while the rules are triggered on mere existence for references. But because we almost always have to convert a *mut pointer to an &mut reference to call methods, we have to ask our callers to uphold the more stringent &mut rules.

https://doc.rust-lang.org/nomicon/aliasing.html

I believe it's okay for a *mut pointer to coexist with an &mut reference. It's just that an &mut reference can't coexist with an &mut reference. So it's possible our documented lifetime requirements are already fine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the documented lifetime requirements described in the issue and the linked Rust Nomicon aliasing guidance. Determine whether the existing requirements distinguish raw *mut pointers from &mut references correctly, then update the relevant documentation if needed and record a clear resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation, security
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.