summaryrefslogtreecommitdiff
path: root/crypto/asn1/asn1_lib.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2020-04-21 19:07:46 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2020-04-21 19:07:46 +0000
commit65aa3028e51cba07879f3dc4608949c5c6b9fcc0 (patch)
tree310ff0dc688f5f84a478a310752abb888ac68e4e /crypto/asn1/asn1_lib.c
parentb6cfecdc04a5a5e42ae4f2b025d8246cc16f3342 (diff)
Notes
Diffstat (limited to 'crypto/asn1/asn1_lib.c')
-rw-r--r--crypto/asn1/asn1_lib.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c
index a7d32ae5e2c3c..366afc5f6c6b5 100644
--- a/crypto/asn1/asn1_lib.c
+++ b/crypto/asn1/asn1_lib.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -268,18 +268,29 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)
return ret;
}
-int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
+int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len_in)
{
unsigned char *c;
const char *data = _data;
+ size_t len;
- if (len < 0) {
+ if (len_in < 0) {
if (data == NULL)
return 0;
- else
- len = strlen(data);
+ len = strlen(data);
+ } else {
+ len = (size_t)len_in;
+ }
+ /*
+ * Verify that the length fits within an integer for assignment to
+ * str->length below. The additional 1 is subtracted to allow for the
+ * '\0' terminator even though this isn't strictly necessary.
+ */
+ if (len > INT_MAX - 1) {
+ ASN1err(0, ASN1_R_TOO_LARGE);
+ return 0;
}
- if ((str->length <= len) || (str->data == NULL)) {
+ if ((size_t)str->length <= len || str->data == NULL) {
c = str->data;
str->data = OPENSSL_realloc(c, len + 1);
if (str->data == NULL) {