Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module variable going out of scope causes open session to be broken and cause SegFault #51

Closed
Magentron opened this issue Feb 21, 2021 · 5 comments · Fixed by #55
Closed

Comments

@Magentron
Copy link
Contributor

This is related to #31.

When doing something like this (pseudo code):

    // function loadModule($path): Module
    return new Module($path);
    
    // function openSession($path, $slot, $pin): Session
    $module = loadModule($path)
    $session = $module->openSession($slot, Pkcs11\CKF_RW_SESSION);
    $session->login(Pkcs11\CKU_USER, $pin);
    $session->getInfo(); // debug
    return $session;
            
    // function getObjects(Session $session)
    return $session->findObjects([
        Pkcs11\CKA_LABEL => 'My name',
    ]);

Before the findObjects() call, the C function pkcs11_shutdown() is called for the module and upon entering findObjects() the session functionList is NULL.

If I put the calls sequentially without functions it does work, so it seems that upon leaving openSession() somehow the PKCS11 shutdown function is called for the module because it going out of scope. This probably should not happen since the session is still open.

How can we solve this best?

@gamringer
Copy link
Owner

I remember having tested this specifically to avoid what you're describing. Obviously, whatever I did was wrong.

I'll look into it. Thanks.

@Magentron
Copy link
Contributor Author

My first hunch would be that reference counting would be necessary.

@gamringer
Copy link
Owner

Yeah, that's what I'm thinking as well.

@Magentron
Copy link
Contributor Author

Let me know if I can help

@vjardin
Copy link
Contributor

vjardin commented Feb 21, 2021

@gamringer

Few months ago, I wanted to introduce a constructor and destructor in order to benefit from PHP's internal ref counters. I feel it could help to solve such issue.

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 a pull request may close this issue.

3 participants