cloudflare / cloudflare/wirefilter

wirefilter_get_last_error() returns a borrowed pointer with no documented lifetime

Open
#193 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.2k
Forks
122
Avg merge
5h 20m
Merged PRs (30d)
4

Description

\`wirefilter_get_last_error()\` (\`ffi/src/lib.rs:223-225\`) is the only string-returning FFI entry point
that hands back a borrowed \`*const c_char\`, pointing into a thread-local \`CString\`'s backing
\`Vec\` (\`ffi/src/cstring.rs:43-49\`). Every other heap-allocated string this API returns comes back
as an owned \`RustAllocatedString\`, freed via \`wirefilter_free_string\`.

Neither the doc comment (\`lib.rs:221\`) nor the generated header states a lifetime for the returned
pointer. The backing buffer can reallocate: \`write_last_error!\` (used at every error site) clears and
re-appends the message (\`cstring.rs:21-33\`), which grows the buffer if the new message is longer than
whatever capacity the previous one left — so the pointer's actual validity is "until the next
\`wirefilter_*\` call on this thread," an implicit contract that isn't written down anywhere a caller
can find it.

Is that the intended contract? If so, could it be stated explicitly in the doc comment and header —
or would it be worth returning an owned string here instead, for consistency with the rest of the FFI
surface?

Found with the [rust-in-peace](https://github.com/scadastrangelove/rust-in-peace) pipeline.

Contributor guide

Open the contributing guide

Research direction

Read ffi/src/lib.rs:221-225 and ffi/src/cstring.rs:21-49, then inspect the generated header and the RustAllocatedString path using wirefilter_free_string. Confirm the intended lifetime and ownership contract for wirefilter_get_last_error(), and consider the documented API behavior or ownership change needed for consistency with the other string-returning FFI entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.