summaryrefslogtreecommitdiff
path: root/crypto/x509/v3_sxnet.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-11-19 13:58:21 +0000
committerMatt Caswell <matt@openssl.org>2020-12-02 10:28:45 +0000
commit61b0fead5e6079ca826594df5b9ca00e65883cb0 (patch)
tree900b7572c85a02a54f5f3e7381d45038dac9a6ca /crypto/x509/v3_sxnet.c
parent89cccbea51fa52a1e4784a9ece35d96e4dcbfd30 (diff)
downloadopenssl-new-61b0fead5e6079ca826594df5b9ca00e65883cb0.tar.gz
Don't Overflow when printing Thawte Strong Extranet Version
When printing human readable info on the Thawte Strong Extranet extension the version number could overflow if the version number == LONG_MAX. This is undefined behaviour. Issue found by OSSFuzz. Reviewed-by: Ben Kaduk <kaduk@mit.edu> (Merged from https://github.com/openssl/openssl/pull/13452)
Diffstat (limited to 'crypto/x509/v3_sxnet.c')
-rw-r--r--crypto/x509/v3_sxnet.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/crypto/x509/v3_sxnet.c b/crypto/x509/v3_sxnet.c
index 76f5eafc73..6e2b796a38 100644
--- a/crypto/x509/v3_sxnet.c
+++ b/crypto/x509/v3_sxnet.c
@@ -57,12 +57,24 @@ IMPLEMENT_ASN1_FUNCTIONS(SXNET)
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
int indent)
{
- long v;
+ int64_t v;
char *tmp;
SXNETID *id;
int i;
- v = ASN1_INTEGER_get(sx->version);
- BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v);
+
+ /*
+ * Since we add 1 to the version number to display it, we don't support
+ * LONG_MAX since that would cause on overflow.
+ */
+ if (!ASN1_INTEGER_get_int64(&v, sx->version)
+ || v >= LONG_MAX
+ || v < LONG_MIN) {
+ BIO_printf(out, "%*sVersion: <unsupported>", indent, "");
+ } else {
+ long vl = (long)v;
+
+ BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", vl + 1, vl);
+ }
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
id = sk_SXNETID_value(sx->ids, i);
tmp = i2s_ASN1_INTEGER(NULL, id->zone);