• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / PyKCS11 / 10442287450
94%

Build:
DEFAULT BRANCH: master
Ran 18 Aug 2024 04:59PM UTC
Jobs 1
Files 22
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

18 Aug 2024 04:26PM UTC coverage: 86.924% (-0.02%) from 86.942%
10442287450

push

github

LudovicRousseau
Fix reference counting in PyKCS11Lib.load()

Fixes incorrect reference counting for PyKCS11Lib._loaded_libs

The bug can be reproduced with the following steps (this case is
implemented in test_specific_load):

- Create an instance of PyKCS11Lib and load a PKCS#11 library
- Load another library using PyKCS11Lib.load method. At this step
  PyKCS11Lib doesn't unload the first library and decrement the
  reference counter on it, i.e. we have two entries in _loaded_libs map
  pointing to the same CPKCS11Lib object.
- Unload the second library: PyKCS11Lib removes the corresponding entry
  from _loaded_libs and invokes self.lib.Unload(), so now we have a
  dangling entry of the first library pointing to the same CPKCS11Lib
  object, on which Unload has been called.
- Load the first library again: PyKCS11Lib calls Duplicate with the
  dangling entry in _loaded_libs.
- Now, try to perform any operation with PyKCS11Lib => causes a segfault

While investigating this problem I found it convenient to add a
PyKCS11Lib.unload method, which allows to explicitly unload the PKCS#11
library. I also added a couple of tests which require two different
PKCS#11 libraries to run, which is not the case in the testing
enviroment (with a single SoftHSM) you are currently using, so I had to
create a temporary copy of libsofthsm2.so to make them work.

By the way, the current implementation of load/unload is not thread
safe, since it operates with an unprotected shared map (_loaded_libs).
However, I'm not sure how much of an issue this is. I'd say, just
marking these methods as non thread safe is pretty much acceptable as
for me.

78 of 79 new or added lines in 5 files covered. (98.73%)

2998 of 3449 relevant lines covered (86.92%)

0.87 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
81.44
0.16% PyKCS11/__init__.py
Jobs
ID Job ID Ran Files Coverage
1 10442287450.1 18 Aug 2024 04:59PM UTC 22
86.92
Source Files on build 10442287450
  • Tree
  • List 22
  • Changed 5
  • Source Changed 0
  • Coverage Changed 5
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 663565a0 on github
  • Prev Build on master (#10291537390)
  • Next Build on master (#10457363263)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc