summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2006-03-28 19:23:48 +0200
committerDr. Stephen Henson <steve@openssl.org>2006-03-28 19:23:48 +0200
commit246e09319c1d2a8140ffe1e5aeb1be26015696f0 (patch)
tree4cf7e9633d8849983bd6a7803fb49c7f64f01a1d /crypto
parentTypo. (diff)
downloadopenssl-246e09319c1d2a8140ffe1e5aeb1be26015696f0.tar.xz
openssl-246e09319c1d2a8140ffe1e5aeb1be26015696f0.zip
Fix bug where freed OIDs could be accessed in EVP_cleanup() by
defering freeing in OBJ_cleanup().
Diffstat (limited to '')
-rw-r--r--crypto/evp/names.c11
-rw-r--r--crypto/objects/obj_dat.c18
2 files changed, 29 insertions, 0 deletions
diff --git a/crypto/evp/names.c b/crypto/evp/names.c
index 88c1e780dd..348df71cba 100644
--- a/crypto/evp/names.c
+++ b/crypto/evp/names.c
@@ -62,12 +62,16 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
+extern int obj_cleanup_defer;
+extern void check_defer(int nid);
+
int EVP_add_cipher(const EVP_CIPHER *c)
{
int r;
r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
if (r == 0) return(0);
+ check_defer(c->nid);
r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
return(r);
}
@@ -80,6 +84,7 @@ int EVP_add_digest(const EVP_MD *md)
name=OBJ_nid2sn(md->type);
r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(const char *)md);
if (r == 0) return(0);
+ check_defer(md->type);
r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(const char *)md);
if (r == 0) return(0);
@@ -88,6 +93,7 @@ int EVP_add_digest(const EVP_MD *md)
r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
if (r == 0) return(0);
+ check_defer(md->pkey_type);
r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
}
@@ -120,4 +126,9 @@ void EVP_cleanup(void)
OBJ_NAME_cleanup(-1);
EVP_PBE_cleanup();
+ if (obj_cleanup_defer == 2)
+ {
+ obj_cleanup_defer = 0;
+ OBJ_cleanup();
+ }
}
diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c
index 7a95c7795a..aca492d1df 100644
--- a/crypto/objects/obj_dat.c
+++ b/crypto/objects/obj_dat.c
@@ -208,8 +208,26 @@ static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *)
static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *)
static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *)
+/* The purpose of obj_cleanup_defer is to avoid EVP_cleanup() attempting
+ * to use freed up OIDs. If neccessary the actual freeing up of OIDs is
+ * delayed.
+ */
+
+int obj_cleanup_defer = 0;
+
+void check_defer(int nid)
+ {
+ if (obj_cleanup_defer && nid >= NUM_NID)
+ obj_cleanup_defer = 1;
+ }
+
void OBJ_cleanup(void)
{
+ if (obj_cleanup_defer)
+ {
+ obj_cleanup_defer = 2;
+ return ;
+ }
if (added == NULL) return;
added->down_load=0;
lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */