Skip to content

Fixed uninitialized variable m_mode in SymmetricCipher.h#13173

Merged
droidmonkey merged 2 commits intokeepassxreboot:developfrom
mateea326:develop
Apr 16, 2026
Merged

Fixed uninitialized variable m_mode in SymmetricCipher.h#13173
droidmonkey merged 2 commits intokeepassxreboot:developfrom
mateea326:develop

Conversation

@mateea326
Copy link
Copy Markdown
Contributor

Description

The SymmetricCipher class used a defaulted constructor (= default), which left the m_mode member variable uninitialized. In C++, enum members are not automatically zero-initialized, meaning that if mode() is called before init(), it returns an indeterminate garbage value from the stack.

This issue was identified via static analysis (cppcheck) as an uninitMemberVar warning in the crypto module.

Fix: Replaced the defaulted constructor with an explicit constructor that initializes m_mode to SymmetricCipher::InvalidMode:

explicit SymmetricCipher()
    : m_mode(InvalidMode)
{
}

Impact:

  • Security & Stability: Ensures the cryptographic object is in a well-defined state immediately upon construction, before init() is called.
  • Logic Integrity: Prevents other components from receiving unpredictable values if they query the cipher's mode prematurely.
  • Code Quality: Resolves a static analysis warning in a security-critical area of the codebase.

Screenshots

N/A — header-only change with no visual output.

Testing strategy

Run cppcheck to confirm the warning is resolved:

cppcheck --enable=warning src/crypto/SymmetricCipher.h

The uninitMemberVar warning for m_mode should no longer appear. Existing unit tests for the crypto module continue to pass unchanged.

Type of change

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

Copilot AI review requested due to automatic review settings March 20, 2026 11:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an uninitialized member in SymmetricCipher (crypto module) by ensuring m_mode is set to a defined value immediately upon construction, avoiding indeterminate results when mode() is called before init().

Changes:

  • Replaced the defaulted constructor with an explicit inline constructor.
  • Initialized m_mode to SymmetricCipher::InvalidMode at construction time.

Comment thread src/crypto/SymmetricCipher.h Outdated
Copilot AI review requested due to automatic review settings April 16, 2026 03:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/crypto/SymmetricCipher.h
@droidmonkey droidmonkey merged commit 4fbdf0c into keepassxreboot:develop Apr 16, 2026
16 checks passed
pull bot pushed a commit to Andyworldclub/keepassxc that referenced this pull request Apr 16, 2026
pull bot pushed a commit to byxy77/keepassxc that referenced this pull request Apr 16, 2026
pull bot pushed a commit to TKaxv-7S/keepassxc that referenced this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants