ProxyClientBase: avoid static_cast to partially destructed object #127

pull ryanofsky wants to merge 1 commits into bitcoin-core:master from ryanofsky:pr/udestroy changing 3 files +17 −13
  1. ryanofsky commented at 7:30 PM on January 15, 2025: collaborator

    This is a bugfix that should fix the UBSan failure reported https://github.com/chaincodelabs/libmultiprocess/issues/125

    In practice there is no real bug here, just like there was no real bug fixed in the recent "ProxyClientBase: avoid static_cast to partially constructed object" change in https://github.com/chaincodelabs/libmultiprocess/pull/121. This is because in practice, ProxyClient subclasses only inherit ProxyClientBase state and do not define any state of their own, so there is nothing bad that could actually happen from static_cast-ing a ProxyClientBase pointer to a ProxyClient pointer inside the ProxyClientBase constructor or destructor.

    However, using static_cast this way technically triggers undefined behavior, and that causes UBSan to fail, so this commit drops the static_cast by making ProxyClient::construct() and ProxyClient::destroy() methods into static methods taking a ProxyClientBase& argument instead of instance methods using *this.

    Fixes #125


    This PR should be a simpler, more robust alternative to a previous for the same bug implemented in #126.

  2. ProxyClientBase: avoid static_cast to partially destructed object
    This is a bugfix that should fix the UBSan failure reported
    https://github.com/chaincodelabs/libmultiprocess/issues/125
    
    In practice there is no real bug here, just like there was no real bug fixed in
    the recent "ProxyClientBase: avoid static_cast to partially constructed object"
    change in https://github.com/chaincodelabs/libmultiprocess/pull/121. This is
    because in practice, ProxyClient subclasses only inherit ProxyClientBase state
    and do not define any state of their own, so there is nothing bad that could
    actually happen from static_cast-ing a ProxyClientBase pointer to a ProxyClient
    pointer inside the ProxyClientBase constructor or destructor.
    
    However, using static_cast this way technically triggers undefined behavior,
    and that causes UBSan to fail, so this commit drops the static_cast by making
    ProxyClient::construct() and ProxyClient::destroy() methods into static methods
    taking a ProxyClientBase& argument instead of instance methods using *this.
    
    Fixes #125
    63a39d4c9b
  3. Sjors commented at 9:28 AM on January 16, 2025: member
  4. sedited approved
  5. sedited commented at 1:19 PM on January 16, 2025: collaborator

    lgtm ACK

    PoxyClient subclasses only inherit ProxyClientBase state and do not define any state of their own

    Seems like this is the correct thing to do in that case anyway.

  6. ryanofsky merged this on Jan 16, 2025
  7. ryanofsky closed this on Jan 16, 2025

  8. ryanofsky commented at 3:37 PM on January 16, 2025: collaborator

    Seems like this is the correct thing to do in that case anyway.

    Yeah I really did not like the previous fix in #126, but this fix is not too bad. The thing I still don't like about this fix is that it makes construct/destroy different than other methods, instead of treating them the same as other methods but just calling them automatically on the client side.

    But unfortunately there doesn't seem to be a good way to call construct/destroy automatically from with ProxyClientBase class without using static_cast or turning them into static methods. I think c++23 with http://wg21.link/P0847 might be able to help with this in the future, but i'm not sure.

  9. Sjors referenced this in commit b298856792 on Jan 16, 2025
  10. Sjors referenced this in commit 2f7dc7d665 on Jan 16, 2025
  11. Sjors referenced this in commit d7013a805b on Jan 17, 2025
  12. Sjors referenced this in commit 42673bf471 on Jan 17, 2025
  13. Sjors referenced this in commit 0ca9eef7a5 on Jan 20, 2025
  14. Sjors referenced this in commit a3be4d6731 on Jan 22, 2025
  15. Sjors referenced this in commit b804b6c4b8 on Jan 23, 2025
  16. Sjors referenced this in commit 0325502620 on Jan 27, 2025
  17. Sjors referenced this in commit 57e60735cf on Jan 27, 2025
  18. Sjors referenced this in commit 71be9377ee on Jan 27, 2025
  19. ryanofsky referenced this in commit 90b116bd70 on Jan 27, 2025
  20. ryanofsky referenced this in commit ada8c1a5b8 on Jan 27, 2025
  21. ryanofsky referenced this in commit 2221c8814d on Jan 27, 2025
  22. Sjors referenced this in commit b66fe2fc03 on Jan 28, 2025
  23. fanquake referenced this in commit ad2f9324c6 on Jan 29, 2025
  24. janus referenced this in commit 311822f35f on Sep 1, 2025
  25. bitcoin-core locked this on Jan 16, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-20 18:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me