From 4bd4afa34e4c67279edee29c93b03bd7ed144d88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bodo=20M=C3=B6ller?= Date: Mon, 19 May 2008 20:45:25 +0000 Subject: [PATCH] Change use of CRYPTO_THREADID so that we always use both the ulong and ptr members. (So if the id_callback is bogus, we still have &errno.) --- CHANGES | 7 ++++++- crypto/cryptlib.c | 17 +++++++++-------- crypto/crypto.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index cf5c17cfca..2f26937ebd 100644 --- a/CHANGES +++ b/CHANGES @@ -4,7 +4,12 @@ Changes between 0.9.8g and 0.9.9 [xx XXX xxxx] - *) To support arbitrarily-typed thread IDs, deprecate the existing + *) Not all of this is true any longer. + Will have to be updated to reflect all subsequent changes to cryptlib.c. + --bodo + + + To support arbitrarily-typed thread IDs, deprecate the existing type-specific APIs for a general purpose CRYPTO_THREADID interface. Applications can choose the thread ID callback type it wishes to register, as before; diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index 73bdfd8ce9..cb858d5519 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -434,29 +434,30 @@ void CRYPTO_set_idptr_callback(void *(*func)(void)) void CRYPTO_THREADID_set(CRYPTO_THREADID *id) { - memset(id, 0, sizeof(*id)); + if (id_callback) + id->ulong = id_callback(); + else + id->ulong = 0; + if (idptr_callback) id->ptr = idptr_callback(); - else if (id_callback) - id->ulong = id_callback(); else id->ptr = &errno; } int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *id1, const CRYPTO_THREADID *id2) { + if (id1->ulong != id2->ulong) + return ((id1->ulong < id2->ulong) ? -1 : 1); if (id1->ptr != id2->ptr) return ((id1->ptr < id2->ptr) ? -1 : 1); - if (id1->ulong != id2->ulong) - return ((id1->ulong < id2->ulong ) ? -1 : 1); return 0; } unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id) { - if (idptr_callback || !id_callback) - return (unsigned long)id->ptr; - return id->ulong; + /* will need further processing to arrive at a good hash (mem_dbg.c uses this) */ + return id->ulong + (unsigned long)id->ptr; } void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dst, const CRYPTO_THREADID *src) diff --git a/crypto/crypto.h b/crypto/crypto.h index bb9b89c6a5..437ed63df1 100644 --- a/crypto/crypto.h +++ b/crypto/crypto.h @@ -307,8 +307,8 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS) * apart when someone decides to extend this in some way. */ typedef struct crypto_threadid { - void *ptr; unsigned long ulong; + void *ptr; } CRYPTO_THREADID; /* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA -- 2.25.1