Commit d9ad3f0
Replace UAF death test with deterministic stale-delegate assertion (#58321)
Summary:
Pull Request resolved: #58321
`SchedulerDelegateInvalidationTest.DelegateDestroyedWithoutError_PendingRenderingUpdateIsUAF`
asserted a real use-after-free through `EXPECT_DEATH`: it destroyed the
`RecordingDelegate`, then drained `pendingRenderingUpdates_` so the queued lambda
dereferenced the freed object, and expected the process to die. Undefined behaviour
is not a reliable process-termination signal, without a sanitizer the freed read
can simply succeed, and gtest then reports `Result: failed to die.` The death test
also has to `fork()` a multi-threaded process.
This replaces the death test with a deterministic assertion on the same property.
Instead of destroying the delegate, the test detaches it via
`Scheduler::setDelegate(nullptr)` and keeps it alive, then drains the pending
rendering update and asserts that the drained lambda still invokes
`schedulerShouldRenderTransactions` on the detached delegate.
That pins exactly the coverage the death test was after: `Scheduler::setDelegate` is
a plain assignment, so a lambda already queued by `uiManagerDidFinishTransaction`
keeps the raw delegate pointer it captured, and draining it after the delegate has
been detached still calls through that pointer, which is a use-after-free when the
delegate has been destroyed rather than merely detached. Same property, no undefined
behaviour and no `fork()`. It matches the shape of the existing
`UnregisterSurface_DoesNotDrainPendingRenderingUpdates` test in the same file.
The underlying window is unchanged: nothing in `Scheduler::setDelegate` cancels
rendering updates that are already queued, so closing it needs a shutdown signal at
the runtime-scheduler level. That is a design decision for the owners rather than a
test fix.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D118205636
fbshipit-source-id: 87cefd8db0d0ebf55025bb60fcdfd1e4cda46e351 parent 8cf8e09 commit d9ad3f0
1 file changed
Lines changed: 28 additions & 21 deletions
File tree
- packages/react-native/ReactCommon/react/renderer/scheduler/tests
Lines changed: 28 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
485 | | - | |
| 484 | + | |
| 485 | + | |
486 | 486 | | |
487 | 487 | | |
488 | | - | |
| 488 | + | |
489 | 489 | | |
490 | | - | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
491 | 501 | | |
492 | | - | |
493 | 502 | | |
494 | 503 | | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
| 504 | + | |
| 505 | + | |
499 | 506 | | |
500 | | - | |
501 | | - | |
502 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
503 | 511 | | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
508 | 516 | | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
513 | 521 | | |
514 | | - | |
515 | 522 | | |
516 | 523 | | |
517 | 524 | | |
| |||
0 commit comments