diff options
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_locl.h | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_old_lib.c | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_dec.c | 7 |
4 files changed, 20 insertions, 16 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 97ce6caeef..ac8da0e61d 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_lib.c,v 1.53 2022/04/28 18:30:57 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_lib.c,v 1.54 2022/05/05 19:18:56 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2021 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -78,10 +78,10 @@ asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, | |||
78 | 78 | ||
79 | int | 79 | int |
80 | asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, | 80 | asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, |
81 | uint32_t *out_length) | 81 | size_t *out_length) |
82 | { | 82 | { |
83 | uint8_t len_bytes; | 83 | uint8_t len_bytes; |
84 | uint32_t length; | 84 | size_t length; |
85 | uint8_t val; | 85 | uint8_t val; |
86 | 86 | ||
87 | /* | 87 | /* |
@@ -127,7 +127,7 @@ asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, | |||
127 | return 0; | 127 | return 0; |
128 | if (der_mode && length == 0 && val == 0) | 128 | if (der_mode && length == 0 && val == 0) |
129 | return 0; | 129 | return 0; |
130 | if (length > (UINT32_MAX >> 8)) | 130 | if (length > (SIZE_MAX >> 8)) |
131 | return 0; | 131 | return 0; |
132 | length = (length << 8) | val; | 132 | length = (length << 8) | val; |
133 | } | 133 | } |
@@ -140,11 +140,12 @@ asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, | |||
140 | int | 140 | int |
141 | asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_tag_class, | 141 | asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_tag_class, |
142 | int *out_constructed, uint32_t *out_tag_number, int *out_indefinite, | 142 | int *out_constructed, uint32_t *out_tag_number, int *out_indefinite, |
143 | uint32_t *out_length) | 143 | size_t *out_length) |
144 | { | 144 | { |
145 | int constructed, indefinite; | 145 | int constructed, indefinite; |
146 | uint32_t tag_number, length; | 146 | uint32_t tag_number; |
147 | uint8_t tag_class; | 147 | uint8_t tag_class; |
148 | size_t length; | ||
148 | 149 | ||
149 | *out_tag_class = 0; | 150 | *out_tag_class = 0; |
150 | *out_constructed = 0; | 151 | *out_constructed = 0; |
@@ -176,8 +177,9 @@ asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number, | |||
176 | CBS *out_content) | 177 | CBS *out_content) |
177 | { | 178 | { |
178 | int constructed, indefinite; | 179 | int constructed, indefinite; |
179 | uint32_t tag_number, length; | 180 | uint32_t tag_number; |
180 | uint8_t tag_class; | 181 | uint8_t tag_class; |
182 | size_t length; | ||
181 | 183 | ||
182 | *out_tag_number = 0; | 184 | *out_tag_number = 0; |
183 | 185 | ||
diff --git a/src/lib/libcrypto/asn1/asn1_locl.h b/src/lib/libcrypto/asn1/asn1_locl.h index 86907aa8f0..79239faea1 100644 --- a/src/lib/libcrypto/asn1/asn1_locl.h +++ b/src/lib/libcrypto/asn1/asn1_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_locl.h,v 1.28 2022/04/28 18:30:57 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_locl.h,v 1.29 2022/05/05 19:18:56 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -196,10 +196,10 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); | |||
196 | int asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, | 196 | int asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, |
197 | int *out_constructed, uint32_t *out_tag_number); | 197 | int *out_constructed, uint32_t *out_tag_number); |
198 | int asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, | 198 | int asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, |
199 | uint32_t *out_length); | 199 | size_t *out_length); |
200 | int asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_class, | 200 | int asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_class, |
201 | int *out_constructed, uint32_t *out_tag_number, int *out_indefinite, | 201 | int *out_constructed, uint32_t *out_tag_number, int *out_indefinite, |
202 | uint32_t *out_length); | 202 | size_t *out_length); |
203 | int asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number, | 203 | int asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number, |
204 | CBS *out_content); | 204 | CBS *out_content); |
205 | 205 | ||
diff --git a/src/lib/libcrypto/asn1/asn1_old_lib.c b/src/lib/libcrypto/asn1/asn1_old_lib.c index e41a5ea257..a4d3cc71b4 100644 --- a/src/lib/libcrypto/asn1/asn1_old_lib.c +++ b/src/lib/libcrypto/asn1/asn1_old_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_old_lib.c,v 1.3 2022/01/14 07:57:17 tb Exp $ */ | 1 | /* $OpenBSD: asn1_old_lib.c,v 1.4 2022/05/05 19:18:56 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -72,8 +72,9 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
72 | int *pclass, long omax) | 72 | int *pclass, long omax) |
73 | { | 73 | { |
74 | int constructed, indefinite; | 74 | int constructed, indefinite; |
75 | uint32_t tag_number, length; | 75 | uint32_t tag_number; |
76 | uint8_t tag_class; | 76 | uint8_t tag_class; |
77 | size_t length; | ||
77 | CBS cbs; | 78 | CBS cbs; |
78 | int ret = 0; | 79 | int ret = 0; |
79 | 80 | ||
@@ -99,7 +100,7 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
99 | * signal an error by setting the 8th bit in the return value... but we | 100 | * signal an error by setting the 8th bit in the return value... but we |
100 | * still provide all of the decoded data. | 101 | * still provide all of the decoded data. |
101 | */ | 102 | */ |
102 | if (length > CBS_len(&cbs)) { | 103 | if (length > CBS_len(&cbs) || length > LONG_MAX) { |
103 | ASN1error(ASN1_R_TOO_LONG); | 104 | ASN1error(ASN1_R_TOO_LONG); |
104 | ret = 0x80; | 105 | ret = 0x80; |
105 | } | 106 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index 0131e3c27c..103774fc19 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_dec.c,v 1.57 2022/05/04 10:57:48 jsing Exp $ */ | 1 | /* $OpenBSD: tasn_dec.c,v 1.58 2022/05/05 19:18:56 jsing Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -1049,9 +1049,10 @@ asn1_check_tag_cbs(CBS *cbs, size_t *out_len, int *out_tag, uint8_t *out_class, | |||
1049 | char *out_indefinite, char *out_constructed, int expected_tag, | 1049 | char *out_indefinite, char *out_constructed, int expected_tag, |
1050 | int expected_class, char optional) | 1050 | int expected_class, char optional) |
1051 | { | 1051 | { |
1052 | uint32_t tag_number, length; | ||
1053 | int constructed, indefinite; | 1052 | int constructed, indefinite; |
1053 | uint32_t tag_number; | ||
1054 | uint8_t tag_class; | 1054 | uint8_t tag_class; |
1055 | size_t length; | ||
1055 | 1056 | ||
1056 | if (out_len != NULL) | 1057 | if (out_len != NULL) |
1057 | *out_len = 0; | 1058 | *out_len = 0; |
@@ -1096,7 +1097,7 @@ asn1_check_tag_cbs(CBS *cbs, size_t *out_len, int *out_tag, uint8_t *out_class, | |||
1096 | return 0; | 1097 | return 0; |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | if (tag_number > INT_MAX || CBS_len(cbs) > INT_MAX) { | 1100 | if (tag_number > INT_MAX) { |
1100 | ASN1error(ASN1_R_TOO_LONG); | 1101 | ASN1error(ASN1_R_TOO_LONG); |
1101 | return 0; | 1102 | return 0; |
1102 | } | 1103 | } |