From 59feca66817f6002326419111aff77dbccdeb871 Mon Sep 17 00:00:00 2001 From: dogo42 Date: Tue, 12 Nov 2024 20:09:45 +0000 Subject: [PATCH 1/3] Fix 'Assertion failed' when encountering zero-length element like CKA_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; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed. --- src/bin/dump/softhsm2-dump-file.cpp | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/bin/dump/softhsm2-dump-file.cpp b/src/bin/dump/softhsm2-dump-file.cpp index 994f67ed8..58680357a 100644 --- a/src/bin/dump/softhsm2-dump-file.cpp +++ b/src/bin/dump/softhsm2-dump-file.cpp @@ -437,13 +437,15 @@ void dump(FILE* stream) } printf("(length %lu)\n", (unsigned long) len); - std::vector value((size_t) len); - if (!readBytes(stream, value)) - { - corrupt(stream); - return; + if (len > 0) { + std::vector value((size_t) len); + if (!readBytes(stream, value)) + { + corrupt(stream); + return; + } + dumpBytes(value); } - dumpBytes(value); } else if (disktype == ATTRMAP_ATTR) { @@ -461,13 +463,15 @@ void dump(FILE* stream) } printf("(length %lu)\n", (unsigned long) len); - std::vector value; - if (!readMap(stream, len, value)) - { - corrupt(stream); - return; - } - dumpMap(value); + if (len > 0) { + std::vector value; + if (!readMap(stream, len, value)) + { + corrupt(stream); + return; + } + dumpMap(value); + } } else if (disktype == MECHSET_ATTR) { From 68492ca51f98b769003012da6426b7765c31fea4 Mon Sep 17 00:00:00 2001 From: dogo42 Date: Fri, 29 Nov 2024 16:20:42 +0000 Subject: [PATCH 2/3] Update src/bin/dump/softhsm2-dump-file.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Björn Svensson --- src/bin/dump/softhsm2-dump-file.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/dump/softhsm2-dump-file.cpp b/src/bin/dump/softhsm2-dump-file.cpp index 58680357a..6bd648aec 100644 --- a/src/bin/dump/softhsm2-dump-file.cpp +++ b/src/bin/dump/softhsm2-dump-file.cpp @@ -463,7 +463,8 @@ void dump(FILE* stream) } printf("(length %lu)\n", (unsigned long) len); - if (len > 0) { + if (len > 0) + { std::vector value; if (!readMap(stream, len, value)) { From d1c2ccfebe4cd2c561fcc6201bb9bc1540498c5c Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Mon, 27 Jan 2025 10:45:17 +0100 Subject: [PATCH 3/3] Update src/bin/dump/softhsm2-dump-file.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Björn Svensson --- src/bin/dump/softhsm2-dump-file.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/dump/softhsm2-dump-file.cpp b/src/bin/dump/softhsm2-dump-file.cpp index 6bd648aec..a8d3a39fb 100644 --- a/src/bin/dump/softhsm2-dump-file.cpp +++ b/src/bin/dump/softhsm2-dump-file.cpp @@ -437,7 +437,8 @@ void dump(FILE* stream) } printf("(length %lu)\n", (unsigned long) len); - if (len > 0) { + if (len > 0) + { std::vector value((size_t) len); if (!readBytes(stream, value)) {