X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fopenssl.git;a=blobdiff_plain;f=crypto%2Fasn1%2Fasn1_lib.c;fp=crypto%2Fasn1%2Fasn1_lib.c;h=d8844eab65217487ff2f3f2a88b3d5bd229b638c;hp=fc4462eb8fe2a6ba053b85225cd5cd98cca05a17;hb=96218269f4c2da82f143727fb7697d572c190bc5;hpb=86f32187c31fcff88253fcead04196563c04be09 diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index fc4462eb8f..d8844eab65 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -275,18 +275,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) {