Skip to content

Fix mutable arguments passed as default arguments.#101

Open
roberthdevries wants to merge 2 commits intowolfSSL:masterfrom
roberthdevries:fix-passing-mutable-argument-as-default
Open

Fix mutable arguments passed as default arguments.#101
roberthdevries wants to merge 2 commits intowolfSSL:masterfrom
roberthdevries:fix-passing-mutable-argument-as-default

Conversation

@roberthdevries
Copy link
Copy Markdown
Contributor

Function defaults are evaluated once, when the function is defined.

The same mutable object is then shared across all calls to the function. If the object is modified, those modifications will persist across calls, which can lead to unexpected behavior.

@roberthdevries roberthdevries force-pushed the fix-passing-mutable-argument-as-default branch from ee90b05 to 786dd94 Compare April 11, 2026 16:55
@roberthdevries
Copy link
Copy Markdown
Contributor Author

One test case test_ecc_make_shared_secret had to be fixed as it apparently relies on using the same random generator.
Reusing the one from the default argument obviously works, but is a dangerous (because implicit and invisible) dependency between the two calls to make a key. In the test case this is now explicit.

Copy link
Copy Markdown
Contributor

@JeremiahM37 JeremiahM37 left a comment

Choose a reason for hiding this comment

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

Skoll Code Review

Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 2 total — 2 posted, 0 skipped
2 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [Critical] Use-after-free: EccPrivate.make_key stores dangling RNG pointer when rng=Nonewolfcrypt/ciphers.py:1192-1207
  • [Medium] Test does not cover the default rng=None path for EccPrivate.make_keytests/test_ciphers.py:616-629

Review generated by Skoll

Comment thread wolfcrypt/ciphers.py Outdated
Comment thread tests/test_ciphers.py
Comment thread wolfcrypt/ciphers.py Outdated
JeremiahM37
JeremiahM37 previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

🐺 Skoll Code Review

Overall recommendation: REQUEST_CHANGES
Findings: 2 total — 2 posted, 0 skipped

Posted findings

  • [High] EccPrivate.make_key: locally-created RNG freed while ECC key still holds pointer via wc_ecc_set_rngwolfcrypt/ciphers.py:1188-1207
  • [Medium] No test exercises the default rng=None path for successful EccPrivate.make_keytests/test_ciphers.py:616-629

Review generated by Skoll via openclaw

Comment thread wolfcrypt/ciphers.py
Comment thread tests/test_ciphers.py
@dgarske
Copy link
Copy Markdown
Contributor

dgarske commented Apr 16, 2026

@roberthdevries please also resolve conflicts. Thanks

@roberthdevries
Copy link
Copy Markdown
Contributor Author

Conflicts are resolved.

@roberthdevries roberthdevries force-pushed the fix-passing-mutable-argument-as-default branch 2 times, most recently from 8066987 to 6a67909 Compare April 17, 2026 19:20
@JeremiahM37 JeremiahM37 requested a review from dgarske April 17, 2026 20:18
Function defaults are evaluated once, when the function is defined.

The same mutable object is then shared across all calls to the function.
If the object is modified, those modifications will persist across calls,
which can lead to unexpected behavior.
Add a test for the case where no random number generator is passed
to EccPrivate.
@roberthdevries roberthdevries force-pushed the fix-passing-mutable-argument-as-default branch from 6a67909 to b4ddce1 Compare April 17, 2026 21:19
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