summaryrefslogtreecommitdiffstats
path: root/src/crypto/bytestring/cbs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bytestring/cbs.c')
-rw-r--r--src/crypto/bytestring/cbs.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/crypto/bytestring/cbs.c b/src/crypto/bytestring/cbs.c
index b417716..10f1a99 100644
--- a/src/crypto/bytestring/cbs.c
+++ b/src/crypto/bytestring/cbs.c
@@ -52,10 +52,8 @@ size_t CBS_len(const CBS *cbs) {
}
int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
- if (*out_ptr != NULL) {
- OPENSSL_free(*out_ptr);
- *out_ptr = NULL;
- }
+ OPENSSL_free(*out_ptr);
+ *out_ptr = NULL;
*out_len = 0;
if (cbs->len == 0) {
@@ -82,8 +80,9 @@ int CBS_contains_zero_byte(const CBS *cbs) {
}
int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len) {
- if (len != cbs->len)
+ if (len != cbs->len) {
return 0;
+ }
return CRYPTO_memcmp(cbs->data, data, len) == 0;
}
@@ -290,7 +289,12 @@ int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
}
if ((data[0] & 0x80) != 0) {
- /* negative number */
+ /* Negative number. */
+ return 0;
+ }
+
+ if (data[0] == 0 && len > 1 && (data[1] & 0x80) == 0) {
+ /* Extra leading zeros. */
return 0;
}