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

Fix 'Assertion failed' in softhsm2-dump-file when encountering a zero-length element #761

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

dogo42
Copy link

@dogo42 dogo42 commented Nov 12, 2024

softhsm2-dump-file dies when it encounters a zero-length element
like CKA_SUBJECT in imported keypairs, but tries to treat the
element as std::vector.

Example output:

...
00 00 00 00 00 00 01 01 CKA_SUBJECT
00 00 00 00 00 00 00 03 byte string attribute
00 00 00 00 00 00 00 00 (length 0)
/usr/include/c++/11/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = unsigned char; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Program received signal SIGABRT, Aborted.

…_SUBJECT is in imported keypairs

Example output:

00 00 00 00 00 00 01 01 CKA_SUBJECT
00 00 00 00 00 00 00 03 byte string attribute
00 00 00 00 00 00 00 00 (length 0)
/usr/include/c++/11/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
…e-fix

Fix 'Assertion failed' when encountering zero-length element like CKA…
src/bin/dump/softhsm2-dump-file.cpp Show resolved Hide resolved
src/bin/dump/softhsm2-dump-file.cpp Outdated Show resolved Hide resolved
Co-authored-by: Björn Svensson <bjorn.a.svensson@est.tech>
{
corrupt(stream);
return;
if (len > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (len > 0) {
if (len > 0)
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the Github GUI lost this change.

@jschlyter jschlyter added the bug Some isn't right label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Some isn't right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants