From: Andy Polyakov Date: Fri, 17 Aug 2018 21:04:03 +0000 (+0200) Subject: asn1/asn_moid.c: overhaul do_create. X-Git-Tag: OpenSSL_1_1_1~93 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=19934970ac8534cd19eb3f64299e5731d97a7a80;p=oweals%2Fopenssl.git asn1/asn_moid.c: overhaul do_create. Original could allocate nid and then bail out on malloc failure. Instead allocate first *then* attempt to create object. Reviewed-by: Kurt Roeckx Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/6998) --- diff --git a/crypto/asn1/asn_moid.c b/crypto/asn1/asn_moid.c index f0b4dab313..68a01f3117 100644 --- a/crypto/asn1/asn_moid.c +++ b/crypto/asn1/asn_moid.c @@ -60,29 +60,20 @@ void ASN1_add_oid_module(void) static int do_create(const char *value, const char *name) { int nid; - ASN1_OBJECT *oid; const char *ln, *ostr, *p; - char *lntmp; + char *lntmp = NULL; + p = strrchr(value, ','); - if (!p) { + if (p == NULL) { ln = name; ostr = value; } else { - ln = NULL; + ln = value; ostr = p + 1; - if (!*ostr) + if (*ostr == '\0') return 0; while (ossl_isspace(*ostr)) ostr++; - } - - nid = OBJ_create(ostr, name, ln); - - if (nid == NID_undef) - return 0; - - if (p) { - ln = value; while (ossl_isspace(*ln)) ln++; p--; @@ -97,10 +88,13 @@ static int do_create(const char *value, const char *name) return 0; } memcpy(lntmp, ln, p - ln); - lntmp[p - ln] = 0; - oid = OBJ_nid2obj(nid); - oid->ln = lntmp; + lntmp[p - ln] = '\0'; + ln = lntmp; } - return 1; + nid = OBJ_create(ostr, name, ln); + + OPENSSL_free(lntmp); + + return nid != NID_undef; }