Codebase list openssl / 8c74c9d
Fix the error handling in i2v_AUTHORITY_KEYID Previously if an error path is entered a leak could result. Reviewed-by: Viktor Dukhovni <viktor@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Matt Caswell 2 years ago
2 changed file(s) with 33 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
3838 STACK_OF(CONF_VALUE)
3939 *extlist)
4040 {
41 char *tmp;
41 char *tmp = NULL;
42 STACK_OF(CONF_VALUE) *origextlist = extlist, *tmpextlist;
43
4244 if (akeyid->keyid) {
4345 tmp = OPENSSL_buf2hexstr(akeyid->keyid->data, akeyid->keyid->length);
44 X509V3_add_value("keyid", tmp, &extlist);
46 if (tmp == NULL) {
47 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_MALLOC_FAILURE);
48 return NULL;
49 }
50 if (!X509V3_add_value("keyid", tmp, &extlist)) {
51 OPENSSL_free(tmp);
52 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_X509_LIB);
53 goto err;
54 }
4555 OPENSSL_free(tmp);
4656 }
47 if (akeyid->issuer)
48 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
57 if (akeyid->issuer) {
58 tmpextlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
59 if (tmpextlist == NULL) {
60 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_X509_LIB);
61 goto err;
62 }
63 extlist = tmpextlist;
64 }
4965 if (akeyid->serial) {
5066 tmp = OPENSSL_buf2hexstr(akeyid->serial->data, akeyid->serial->length);
51 X509V3_add_value("serial", tmp, &extlist);
67 if (tmp == NULL) {
68 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_MALLOC_FAILURE);
69 goto err;
70 }
71 if (!X509V3_add_value("serial", tmp, &extlist)) {
72 OPENSSL_free(tmp);
73 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_X509_LIB);
74 goto err;
75 }
5276 OPENSSL_free(tmp);
5377 }
5478 return extlist;
79 err:
80 if (origextlist == NULL)
81 sk_CONF_VALUE_pop_free(extlist, X509V3_conf_free);
82 return NULL;
5583 }
5684
5785 /*-