Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-free with closures in JS bindings #1385

Merged
merged 3 commits into from
Mar 22, 2019

Commits on Mar 21, 2019

  1. Fix use-after-free with closures in JS bindings

    This commit fixes an erroneous use-after-free which can happen in
    erroneous situations in JS. It's intended that if you invoke a closure
    after its environment has been destroyed that you'll immediately get an
    error from Rust saying so. The JS binding generation for mutable
    closures, however, accidentally did not protect against this.
    
    Each closure has an internal reference count which is incremented while
    being invoked and decremented when the invocation finishes and also when
    the `Closure` in Rust is dropped. That means there's two branches where
    the reference count reaches zero and the internal pointer stored in JS
    needs to be set to zero. Only one, however, actually set the pointer to
    zero!
    
    This means that if a closure was destroyed while it was being invoked it
    would not correctly set its internal pointer to zero. A further
    invocation of the closure would then pass as seemingly valid pointer
    into Rust, causing a use-after-free.
    
    A test isn't included here specifically for this because our CI has
    started failing left-and-right over this test, so this commit will
    hopefully just make our CI green!
    alexcrichton committed Mar 21, 2019
    Configuration menu
    Copy the full SHA
    2ff2e25 View commit details
    Browse the repository at this point in the history

Commits on Mar 22, 2019

  1. Update crates/cli-support/src/js/closures.rs

    Co-Authored-By: alexcrichton <alex@alexcrichton.com>
    fitzgen and alexcrichton committed Mar 22, 2019
    Configuration menu
    Copy the full SHA
    407bc5d View commit details
    Browse the repository at this point in the history
  2. Update crates/cli-support/src/js/closures.rs

    Co-Authored-By: alexcrichton <alex@alexcrichton.com>
    fitzgen and alexcrichton committed Mar 22, 2019
    Configuration menu
    Copy the full SHA
    6c62d54 View commit details
    Browse the repository at this point in the history