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:
coverage: 88.33% (+0.02%) from 88.308%
when pulling 1287b8ae68b7a0e4906eaab4cb63abab20b99733 on fuzzykat:bugfix/cached_libname
into eaded3bb3735872ba28858a58e0fa1e3cb1802fa on LudovicRousseau:master.
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 toself.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:which in my case ended up with a segfault. This PR proposes a fix for the problem.