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 inconsistent mutex unlocking due to double slot execution #1691

Merged
merged 1 commit into from
Mar 10, 2018

Conversation

phoerious
Copy link
Member

@phoerious phoerious commented Mar 9, 2018

Description

Fixes crash on Windows due to double mutex unlock. Resolves #1561.

Motivation and context

On Windows, the rejected() slot of the Auto-Type selection dialog was called twice on screen lock, resulting in a double mutex unlock. I have no idea why it's doing that (perhaps a bug introduced in Qt 5.10), but this patch works around it by making sure the mutex is locked before we try to unlock it.

In addition, I added another mutex for the actual auto-typing (not just the dialog) to ensure we are never auto-typing two sequences at the same time (not that this was an issue, but when we're already at it...)

How has this been tested?

Manually on Windows. I could not reproduce the crash anymore after applying the patch.

Types of changes

  • ✅ Bug fix (non-breaking change which fixes an issue)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]

@phoerious phoerious added this to the v2.3.2 milestone Mar 9, 2018
@phoerious phoerious requested a review from a team March 9, 2018 20:43
@phoerious phoerious mentioned this pull request Mar 9, 2018
@droidmonkey droidmonkey self-requested a review March 9, 2018 20:54
@TheZ3ro
Copy link
Contributor

TheZ3ro commented Mar 9, 2018

In addition, I added another mutex for the actual auto-typing (not just the dialog) to ensure we are never auto-typing two sequences at the same time (not that this was an issue, but when we're already at it...)

This was already implemented since the m_inAutoType was locked before the executeAutoTypeActions and unlocked after.

If the problem was a double mutex unlock, the easy fix (tryLocking before unlocking) is just a one line fix:

void AutoType::resetInAutoType()
{
    Q_UNUSED(m_inAutoType.tryLock());
    m_inAutoType.unlock();

    emit autotypeRejected();
}

Inserting another mutex is useless, the first one already take care about everything

@phoerious
Copy link
Member Author

phoerious commented Mar 9, 2018

Yes, for global Auto-Type, the outer mutex also covers the inner one, but non-global Auto-Type should have a mutex as well.
The global one is really just for ensuring that we don't open two or more global Auto-Type dialogs at the same time. The inner one is for ensuring that we never auto-type two sequences at the same time (no matter if global or not).

Previously, performAutoType used the same mutex, but it makes a lot more sense to keep it local to the function doing the actual work, which prevents a lot of errors. By splitting the logic into two distinct mutexes, I can keep one entirely inside one function and spread the other one over as few as possible (i.e., one that locks and two which unlock, which is far from ideal, but better than having all sorts of functions taking care of it). I also don't mix our two use cases, which are preventing double dialogs and preventing double Auto-Type, making the semantics behind the mutexes a lot more transparent.

@TheZ3ro
Copy link
Contributor

TheZ3ro commented Mar 9, 2018

I agree that the double use case mix things up a little bit.

The old single-mutex approach already locked multiple global-autotype/single-autotype and mixed global - single autotype.
Having a mutex on the executeAutotypeActions (in the function itself or outside it) is enough since both scenario uses that function.
Having 2 mutex seems redundant to me when a single one does the job in both cases.

Double dialog is file if the single mutex locks/unlocks fine

@phoerious
Copy link
Member Author

phoerious commented Mar 9, 2018

The problem with having only a single mutex is that it's quite easy to produce deadlocks by re-entrance and we cannot set the mutex to be recursive, because we are working only in a single thread.

@TheZ3ro
Copy link
Contributor

TheZ3ro commented Mar 9, 2018

So it's fine by me

@phoerious
Copy link
Member Author

Then please approve. 😉

@phoerious phoerious merged commit 2b91e4d into release/2.3.2 Mar 10, 2018
@phoerious phoerious deleted the hotfix/1561-auto-type-crash-on-lock branch March 10, 2018 09:52
@TheZ3ro
Copy link
Contributor

TheZ3ro commented Mar 10, 2018

I was waiting for @droidmonkey since he explicitly self requested a review 😅

@droidmonkey
Copy link
Member

Lol sorry I didnt see the core developers already in place. I wanted to run this on my machine to test that it fixed the issue, i trust you guys

droidmonkey added a commit that referenced this pull request May 8, 2018
- Enable high entropy ASLR on Windows [#1747]
- Enhance favicon fetching [#1786]
- Fix crash on Windows due to autotype [#1691]
- Fix dark tray icon changing all icons [#1680]
- Fix --pw-stdin not using getPassword function [#1686]
- Fix placeholders being resolved in notes [#1907]
- Enable auto-type start delay to be configurable [#1908]
- Browser: Fix native messaging reply size [#1719]
- Browser: Increase maximum buffer size [#1720]
- Browser: Enhance usability and functionality [#1810, #1822, #1830, #1884, #1906]
- SSH Agent: Parse aes-256-cbc/ctr keys [#1682]
- SSH Agent: Enhance usability and functionality [#1677, #1679, #1681, #1787]
@phoerious phoerious added pr: bugfix Pull request that fixes a bug and removed bug labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Windows pr: bugfix Pull request that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants