Skip to content

fix: keep callback userdata valid across moves - #693

Open
dajiaohuang wants to merge 1 commit into
sagebind:mainfrom
dajiaohuang:fix/callback-userdata-aliasing
Open

dajiaohuang wants to merge 1 commit into
sagebind:mainfrom
dajiaohuang:fix/callback-userdata-aliasing

Conversation

@dajiaohuang

Copy link
Copy Markdown

Fixes #691.

Easy2::default_configure previously derived libcurl callback userdata by casting a shared reference to Inner into a mutable pointer. The callback later mutates the handler through that pointer, and the stored pointer can also outlive the temporary borrow and be invalidated as Easy2 moves.

Keep Inner in an owning raw-pointer wrapper created with Box::into_raw, and pass that allocation pointer to libcurl callbacks. The wrapper provides the existing field access and reconstructs the Box on drop, after curl_easy_cleanup has run. Add a synthetic callback regression that moves the owner and invokes the write callback through the saved userdata.

Validation:

  • cargo test --offline --package curl --lib --no-default-features — 6 passed.
  • rustfmt --check --edition 2018 src/easy/handler.rs — passed.
  • git diff --check — passed.
  • Miri was unavailable on the installed Windows toolchain; the issue includes the Miri failure, with an independent BorrowSanitizer confirmation.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aliasing violation in src/easy/handler.rs (tree/stacked borrow violation)

1 participant