diff --git a/src/bin/dump/softhsm2-dump-file.cpp b/src/bin/dump/softhsm2-dump-file.cpp index 994f67ed..6bd648ae 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,16 @@ void dump(FILE* stream) } printf("(length %lu)\n", (unsigned long) len); - std::vector value; - if (!readMap(stream, len, value)) + if (len > 0) { - corrupt(stream); - return; - } - dumpMap(value); + std::vector value; + if (!readMap(stream, len, value)) + { + corrupt(stream); + return; + } + dumpMap(value); + } } else if (disktype == MECHSET_ATTR) {