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

Problem while closing library that is initialized but improperly finalized. #171

Closed
halderen opened this issue Nov 10, 2015 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@halderen
Copy link
Member

There is a segmentation violation when closing the softhsm2 library when it was opened dynamically using dlopen(). It happens when the library is initialized using C_Initialize(), but no C_Finalize is called prior unloading the library.

int
main(int argc, char** argv)
{
    int i;
    void* handle;
    void* symbol;
    CK_FUNCTION_LIST_PTR table;
    CK_SESSION_HANDLE session;
    handle = dlopen("/usr/local/lib/softhsm/libsofthsm2.so", RTLD_NOW | RTLD_LOCAL);
    symbol = dlsym(handle, "C_GetFunctionList");
    ((CK_C_GetFunctionList) symbol)(&table);
    table->C_Initialize(&InitArgs);
    return 0;
}

Note the dlclose is implicit here, but an explicit dlclose as the end results in about the same. It will result in

Program terminated with signal 11, Segmentation fault.
#0  0x00007f7cc62ad943 in SoftHSM::C_Finalize (this=0x11d5390, pReserved=0x0)
    at SoftHSM.cpp:513
513     if (handleManager != NULL) delete handleManager;

Simply because all the vptr is already gone. My personal take would be to remove the libcleanup() function alltogether, it is an attempt to close off properly when the calling program has not done so (which is the case above), but that won't always work properly.

@bellgrim bellgrim added the bug label Dec 10, 2015
@bellgrim bellgrim added this to the 2.1.0 milestone Dec 10, 2015
bellgrim added a commit to bellgrim/SoftHSMv2 that referenced this issue Dec 10, 2015
@bellgrim
Copy link
Contributor

Thank you for the report, this has now been fixed in #175

bellgrim added a commit to bellgrim/SoftHSMv2 that referenced this issue Dec 11, 2015
…C_Finalize(). Needed when e.g. initalizing again using another mutex config.
bellgrim added a commit to bellgrim/SoftHSMv2 that referenced this issue Dec 17, 2015
bellgrim added a commit to bellgrim/SoftHSMv2 that referenced this issue Dec 17, 2015
…C_Finalize(). Needed when e.g. initalizing again using another mutex config.
bellgrim added a commit that referenced this issue Dec 17, 2015
Issue #171: Problem while closing library that is initialized but imp…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants