LudovicRousseau / PyKCS11

PKCS#11 Wrapper for Python
GNU General Public License v2.0
99 stars 35 forks source link

Fix incorrect application state after a failed attempt to load a PKCS#11 library #112

Closed fuzzykat closed 7 months ago

fuzzykat commented 7 months ago

Calling the method self.pkcs11.load(lib) twice leads to an incorrect state of the application, if the first attempt to load a library failed. The problem is that code in __init__.py fills the map _loaded_libs with the library name before the library is actually loaded, and then the next call to self.pkcs11.load(lib) finds the cached library (which wasn't properly loaded) and finishes successfully. The bug can be reproduced by simply setting an invalid PKCS#11 library name and executing the unit tests:

export PYKCS11LIB=/path/to/invalid/lib.so
./run_test.py

which in my case ended up with a segfault. This PR proposes a fix for the problem.

coveralls commented 7 months ago

Coverage Status

coverage: 88.33% (+0.02%) from 88.308% when pulling 1287b8ae68b7a0e4906eaab4cb63abab20b99733 on fuzzykat:bugfix/cached_libname into eaded3bb3735872ba28858a58e0fa1e3cb1802fa on LudovicRousseau:master.

LudovicRousseau commented 7 months ago

Thanks