diff options
author | Jack Lloyd <[email protected]> | 2016-02-09 07:29:49 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-02-09 07:29:49 -0500 |
commit | 7c57af4436e765be9fc3fea37c35d452b0ecb3c9 (patch) | |
tree | 49b174900a3ee9a3cc889dcd4ca1e64dd23b8938 /src/lib/asn1/der_enc.cpp | |
parent | 86dd5511d873846f57b235531dda428b9498cf6a (diff) |
Add asserts to help out Coverity
It somehow deduces an input that is both > 0 and for which high_bit
never finds a bit set and returns 0. In both cases that would lead to
block being 0 and a negative shift.
Diffstat (limited to 'src/lib/asn1/der_enc.cpp')
-rw-r--r-- | src/lib/asn1/der_enc.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/lib/asn1/der_enc.cpp b/src/lib/asn1/der_enc.cpp index 871171153..c5c2b4803 100644 --- a/src/lib/asn1/der_enc.cpp +++ b/src/lib/asn1/der_enc.cpp @@ -34,6 +34,8 @@ secure_vector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) size_t blocks = high_bit(type_tag) + 6; blocks = (blocks - (blocks % 7)) / 7; + BOTAN_ASSERT(blocks > 0, "Math works"); + encoded_tag.push_back(class_tag | 0x1F); for(size_t i = 0; i != blocks - 1; ++i) encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-i-1)) & 0x7F)); |