Fix crash on selecting “Mask values” in transaction view #774

pull theStack wants to merge 1 commits into bitcoin-core:master from theStack:202310-gui-fix_mask_values_crash_in_transaction_view changing 1 files +3 −0
  1. theStack commented at 9:20 pm on October 30, 2023: contributor

    This PR fixes a crash bug that can be caused with the following steps:

    • change to the “Transactions” view
    • right-click on an arbitrary transaction -> “Show transaction details”
    • close the transaction detail window again
    • select menu item “Settings” -> “Mask values”

    The problem is that the list of opened dialogs, tracked in the member variable m_opened_dialogs (introduced in #708, commit 4492de1be11f4131811f504a037342c78f480e20), is only ever appended with newly opened transaction detail dialog pointers, but never removed. This leads to dangling pointers in the list, and if the “Mask values” menu item is selected, a crash is caused in the course of trying to close the opened transaction detail dialogs (see closeOpenedDialogs() method). Fix this by removing a pointer of the list if the corresponding widget is destroyed.

  2. DrahtBot commented at 9:20 pm on October 30, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK pablomartin4btc, furszy, achow101, hebasto

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. theStack commented at 9:21 pm on October 30, 2023: contributor
    Tagging @furszy who signaled interest in this crash bug while talking earlier.
  4. theStack force-pushed on Oct 30, 2023
  5. DrahtBot added the label CI failed on Oct 30, 2023
  6. DrahtBot removed the label CI failed on Oct 30, 2023
  7. gui: fix crash on selecting "Mask values" in transaction view
    This commits fixes a crash bug that can be caused with the following steps:
    - change to the "Transactions" view
    - right-click on an arbitrary transaction -> "Show transaction details"
    - close the transaction detail window again
    - select "Settings" -> "Mask values"
    
    The problem is that the list of opened dialogs, tracked in the member
    variable `m_opened_dialogs`, is only ever appended with newly opened
    transaction detail dialog pointers, but never removed. This leads to
    dangling pointers in the list, and if the "Mask values" menu item is
    selected, a crash is caused in the course of trying to close the opened
    transaction detail dialogs (see `closeOpenedDialogs()` method). Fix this
    by removing the pointer from the list if the corresponding widget is
    destroyed.
    e26e665f9f
  8. theStack force-pushed on Oct 30, 2023
  9. pablomartin4btc commented at 11:29 pm on October 30, 2023: contributor

    Concept ACK

    Good catch! I’m the culprit perhaps, I’ll take a deeper look at it ASAP!

    I took a quick look at the code and LGTM, the original issue with the multiple transaction details dialogs was caught by another reviewer and solved on the original PR #708 but this is a different one.

  10. theStack commented at 11:33 pm on October 30, 2023: contributor
    Just force-pushed a much simpler version (only three lines) which avoids the circular dependency and the introduction of new methods. The old version is still available here for reference (or in case the current solution has problems that I’m not aware of): https://github.com/bitcoin-core/gui/commit/757e58d6f4cc9592de3d960df0eee44f1cbf6c7d
  11. pablomartin4btc approved
  12. pablomartin4btc commented at 4:49 am on October 31, 2023: contributor

    tACK e26e665f9f64a962dd56053be817cc953e714847

    I easily managed to reproduce the issue in masterfollowing the instructions in the description of the PR (bitcoin-qtcrashes with:Segmentation fault (core dumped)output).

    I couldn’t reproduce the error anymore while using the new bitcoin-qt version compiled with this branch.

    I’d prefer this second approach better. Thank for fixing it!

  13. MarnixCroes approved
  14. MarnixCroes commented at 8:41 am on October 31, 2023: contributor
    tack e26e665f9f64a962dd56053be817cc953e714847
  15. furszy commented at 12:29 pm on October 31, 2023: member

    Could also:

    0diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
    1@@ -656,7 +656,7 @@
    2 {
    3     // close all dialogs opened from this view
    4     for (QDialog* dlg : m_opened_dialogs) {
    5-        dlg->close();
    6+        if (dlg) dlg->close();
    7     }
    8     m_opened_dialogs.clear();
    9 }
    
  16. furszy commented at 12:29 pm on October 31, 2023: member
    utACK e26e665f9
  17. theStack commented at 1:02 pm on October 31, 2023: contributor

    Could also:

    0diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
    1@@ -656,7 +656,7 @@
    2 {
    3     // close all dialogs opened from this view
    4     for (QDialog* dlg : m_opened_dialogs) {
    5-        dlg->close();
    6+        if (dlg) dlg->close();
    7     }
    8     m_opened_dialogs.clear();
    9 }
    

    This wouldn’t change the behaviour, as a pointer in the m_opened_dialogs list is not set to NULL after the dialog it points to is destroyed. I think it could work if we used guarded pointers like QPointer in the list instead, IIUC (but we don’t seem to use them anywhere in our codebase).

  18. achow101 commented at 5:51 pm on October 31, 2023: member
    Should this be backported?
  19. theStack commented at 6:21 pm on October 31, 2023: contributor

    Should this be backported?

    Yes, I think so. The bug first occured with release 25.0 (according to git tag --contains 4492de1be11 in the main repo), so backporting to 25.x and 26.x would make sense.

  20. achow101 commented at 6:29 pm on October 31, 2023: member
    ACK e26e665f9f64a962dd56053be817cc953e714847
  21. pablomartin4btc commented at 9:18 pm on October 31, 2023: contributor

    I do agree with @theStack backporting (checked it with the git tag command) since the issue technically is the “conflict” between these 2 lines: https://github.com/bitcoin-core/gui/blob/3c0b66c2ece7695ab59f466d7b4d81a4c18ffd76/src/qt/transactionview.cpp#L532-L533

    The last one (#L533) was added by the #708 (merged in v25 - I wanted to say I’m innocent but no haha), so another way to solve this issue is just by removing #L532, which I’ve tested and works fine.

  22. hebasto renamed this:
    gui: fix crash on selecting "Mask values" in transaction view
    Fix crash on selecting "Mask values" in transaction view
    on Nov 1, 2023
  23. hebasto added the label Needs backport (25.x) on Nov 1, 2023
  24. hebasto added the label Needs backport (26.x) on Nov 1, 2023
  25. hebasto approved
  26. hebasto commented at 9:44 am on November 1, 2023: member
    ACK e26e665f9f64a962dd56053be817cc953e714847, tested on Ubuntu 22.04.
  27. fanquake commented at 9:51 am on November 1, 2023: member
    Will backport this once merged.
  28. hebasto commented at 9:52 am on November 1, 2023: member

    https://github.com/bitcoin-core/gui/blob/3c0b66c2ece7695ab59f466d7b4d81a4c18ffd76/src/qt/transactionview.cpp#L532-L533

    The last one (#L533) was added by the #708 (merged in v25 - I wanted to say I’m innocent but no haha), so another way to solve this issue is just by removing #L532, which I’ve tested and works fine.

    It will still allow to grow the size of m_opened_dialogs unbounded.

    The current PR branch tackles with m_opened_dialogs size, which is the optimum solution.

  29. hebasto merged this on Nov 1, 2023
  30. hebasto closed this on Nov 1, 2023

  31. fanquake cross-referenced this on Nov 1, 2023 from issue [26.x] Backports for rc2 by fanquake
  32. fanquake removed the label Needs backport (26.x) on Nov 1, 2023
  33. fanquake commented at 10:02 am on November 1, 2023: member
  34. fanquake referenced this in commit e097d4cb53 on Nov 1, 2023
  35. theStack deleted the branch on Nov 1, 2023
  36. fanquake referenced this in commit 67b2512560 on Nov 1, 2023
  37. fanquake commented at 1:10 pm on November 1, 2023: member
    Pulled this into a branch for 25.x backporting. See https://github.com/bitcoin/bitcoin/pull/28768.
  38. fanquake removed the label Needs backport (25.x) on Nov 1, 2023
  39. fanquake referenced this in commit 647bdfcf51 on Nov 1, 2023
  40. fanquake cross-referenced this on Nov 1, 2023 from issue [25.x] Backports by fanquake

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-22 22:20 UTC

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