cooljeanius / trousers-0.3.11.2

forked from Sourceforge to get it working on OSX
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Fix code scanning alert no. 5: Potential use after free #7

Closed cooljeanius closed 3 weeks ago

cooljeanius commented 3 weeks ago

Fixes https://github.com/cooljeanius/trousers-0.3.11.2/security/code-scanning/5

To fix the use-after-free error, we need to ensure that rsakey->key.algorithmParms.parms is not accessed after it has been freed unless it has been successfully reallocated. The best way to fix this is to set rsakey->key.algorithmParms.parms to NULL immediately after freeing it. This way, any subsequent access to this pointer will be safe, as accessing a NULL pointer will not lead to undefined behavior.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.