| OLD | NEW |
| (Empty) |
| 1 diff --git a/lib/ssl/ssl3con.c b/lib/ssl/ssl3con.c | |
| 2 index 1394542..d7d186a 100644 | |
| 3 --- a/lib/ssl/ssl3con.c | |
| 4 +++ b/lib/ssl/ssl3con.c | |
| 5 @@ -6049,7 +6049,6 @@ SSL3_ShutdownServerCache(void) | |
| 6 } | |
| 7 | |
| 8 PZ_Unlock(symWrapKeysLock); | |
| 9 - ssl_FreeSessionCacheLocks(); | |
| 10 return SECSuccess; | |
| 11 } | |
| 12 | |
| 13 @@ -6102,7 +6101,7 @@ getWrappingKey(sslSocket *ss, | |
| 14 | |
| 15 pSymWrapKey = &symWrapKeys[symWrapMechIndex].symWrapKey[exchKeyType]; | |
| 16 | |
| 17 - ssl_InitSessionCacheLocks(PR_TRUE); | |
| 18 + ssl_InitSessionCacheLocks(); | |
| 19 | |
| 20 PZ_Lock(symWrapKeysLock); | |
| 21 | |
| 22 diff --git a/lib/ssl/sslimpl.h b/lib/ssl/sslimpl.h | |
| 23 index d47eb28..c0e3a0b 100644 | |
| 24 --- a/lib/ssl/sslimpl.h | |
| 25 +++ b/lib/ssl/sslimpl.h | |
| 26 @@ -2029,9 +2029,7 @@ extern SECStatus ssl_InitSymWrapKeysLock(void); | |
| 27 | |
| 28 extern SECStatus ssl_FreeSymWrapKeysLock(void); | |
| 29 | |
| 30 -extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit); | |
| 31 - | |
| 32 -extern SECStatus ssl_FreeSessionCacheLocks(void); | |
| 33 +extern SECStatus ssl_InitSessionCacheLocks(void); | |
| 34 | |
| 35 /**************** DTLS-specific functions **************/ | |
| 36 extern void dtls_FreeQueuedMessage(DTLSQueuedMessage *msg); | |
| 37 diff --git a/lib/ssl/sslnonce.c b/lib/ssl/sslnonce.c | |
| 38 index 4804cb8..99591cc 100644 | |
| 39 --- a/lib/ssl/sslnonce.c | |
| 40 +++ b/lib/ssl/sslnonce.c | |
| 41 @@ -35,93 +35,55 @@ static PZLock *cacheLock = NULL; | |
| 42 #define LOCK_CACHE lock_cache() | |
| 43 #define UNLOCK_CACHE PZ_Unlock(cacheLock) | |
| 44 | |
| 45 -static SECStatus | |
| 46 -ssl_InitClientSessionCacheLock(void) | |
| 47 -{ | |
| 48 - cacheLock = PZ_NewLock(nssILockCache); | |
| 49 - return cacheLock ? SECSuccess : SECFailure; | |
| 50 -} | |
| 51 - | |
| 52 -static SECStatus | |
| 53 -ssl_FreeClientSessionCacheLock(void) | |
| 54 -{ | |
| 55 - if (cacheLock) { | |
| 56 - PZ_DestroyLock(cacheLock); | |
| 57 - cacheLock = NULL; | |
| 58 - return SECSuccess; | |
| 59 - } | |
| 60 - PORT_SetError(SEC_ERROR_NOT_INITIALIZED); | |
| 61 - return SECFailure; | |
| 62 -} | |
| 63 - | |
| 64 -static PRBool LocksInitializedEarly = PR_FALSE; | |
| 65 +static PRCallOnceType lockOnce; | |
| 66 | |
| 67 +/* FreeSessionCacheLocks is a callback from NSS_RegisterShutdown which destroys | |
| 68 + * the session cache locks on shutdown and resets them to their initial | |
| 69 + * state. */ | |
| 70 static SECStatus | |
| 71 -FreeSessionCacheLocks() | |
| 72 +FreeSessionCacheLocks(void *appData, void *nssData) | |
| 73 { | |
| 74 - SECStatus rv1, rv2; | |
| 75 - rv1 = ssl_FreeSymWrapKeysLock(); | |
| 76 - rv2 = ssl_FreeClientSessionCacheLock(); | |
| 77 - if ((SECSuccess == rv1) && (SECSuccess == rv2)) { | |
| 78 - return SECSuccess; | |
| 79 - } | |
| 80 - return SECFailure; | |
| 81 -} | |
| 82 + static const PRCallOnceType pristineCallOnce; | |
| 83 + SECStatus rv; | |
| 84 | |
| 85 -static SECStatus | |
| 86 -InitSessionCacheLocks(void) | |
| 87 -{ | |
| 88 - SECStatus rv1, rv2; | |
| 89 - PRErrorCode rc; | |
| 90 - rv1 = ssl_InitSymWrapKeysLock(); | |
| 91 - rv2 = ssl_InitClientSessionCacheLock(); | |
| 92 - if ((SECSuccess == rv1) && (SECSuccess == rv2)) { | |
| 93 - return SECSuccess; | |
| 94 - } | |
| 95 - rc = PORT_GetError(); | |
| 96 - FreeSessionCacheLocks(); | |
| 97 - PORT_SetError(rc); | |
| 98 - return SECFailure; | |
| 99 -} | |
| 100 - | |
| 101 -/* free the session cache locks if they were initialized early */ | |
| 102 -SECStatus | |
| 103 -ssl_FreeSessionCacheLocks() | |
| 104 -{ | |
| 105 - PORT_Assert(PR_TRUE == LocksInitializedEarly); | |
| 106 - if (!LocksInitializedEarly) { | |
| 107 + if (!cacheLock) { | |
| 108 PORT_SetError(SEC_ERROR_NOT_INITIALIZED); | |
| 109 return SECFailure; | |
| 110 } | |
| 111 - FreeSessionCacheLocks(); | |
| 112 - LocksInitializedEarly = PR_FALSE; | |
| 113 - return SECSuccess; | |
| 114 -} | |
| 115 | |
| 116 -static PRCallOnceType lockOnce; | |
| 117 + PZ_DestroyLock(cacheLock); | |
| 118 + cacheLock = NULL; | |
| 119 | |
| 120 -/* free the session cache locks if they were initialized lazily */ | |
| 121 -static SECStatus | |
| 122 -ssl_ShutdownLocks(void *appData, void *nssData) | |
| 123 -{ | |
| 124 - PORT_Assert(PR_FALSE == LocksInitializedEarly); | |
| 125 - if (LocksInitializedEarly) { | |
| 126 - PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); | |
| 127 - return SECFailure; | |
| 128 + rv = ssl_FreeSymWrapKeysLock(); | |
| 129 + if (rv != SECSuccess) { | |
| 130 + return rv; | |
| 131 } | |
| 132 - FreeSessionCacheLocks(); | |
| 133 - memset(&lockOnce, 0, sizeof(lockOnce)); | |
| 134 + | |
| 135 + lockOnce = pristineCallOnce; | |
| 136 return SECSuccess; | |
| 137 } | |
| 138 | |
| 139 +/* InitSessionCacheLocks is called, protected by lockOnce, to create the | |
| 140 + * session cache locks. */ | |
| 141 static PRStatus | |
| 142 -initSessionCacheLocksLazily(void) | |
| 143 +InitSessionCacheLocks(void) | |
| 144 { | |
| 145 - SECStatus rv = InitSessionCacheLocks(); | |
| 146 - if (SECSuccess != rv) { | |
| 147 + SECStatus rv; | |
| 148 + | |
| 149 + cacheLock = PZ_NewLock(nssILockCache); | |
| 150 + if (cacheLock == NULL) { | |
| 151 return PR_FAILURE; | |
| 152 } | |
| 153 - rv = NSS_RegisterShutdown(ssl_ShutdownLocks, NULL); | |
| 154 + rv = ssl_InitSymWrapKeysLock(); | |
| 155 + if (rv != SECSuccess) { | |
| 156 + PRErrorCode error = PORT_GetError(); | |
| 157 + PZ_DestroyLock(cacheLock); | |
| 158 + cacheLock = NULL; | |
| 159 + PORT_SetError(error); | |
| 160 + return PR_FAILURE; | |
| 161 + } | |
| 162 + | |
| 163 + rv = NSS_RegisterShutdown(FreeSessionCacheLocks, NULL); | |
| 164 PORT_Assert(SECSuccess == rv); | |
| 165 if (SECSuccess != rv) { | |
| 166 return PR_FAILURE; | |
| 167 @@ -129,35 +91,19 @@ initSessionCacheLocksLazily(void) | |
| 168 return PR_SUCCESS; | |
| 169 } | |
| 170 | |
| 171 -/* lazyInit means that the call is not happening during a 1-time | |
| 172 - * initialization function, but rather during dynamic, lazy initialization | |
| 173 - */ | |
| 174 SECStatus | |
| 175 -ssl_InitSessionCacheLocks(PRBool lazyInit) | |
| 176 +ssl_InitSessionCacheLocks() | |
| 177 { | |
| 178 - if (LocksInitializedEarly) { | |
| 179 - return SECSuccess; | |
| 180 - } | |
| 181 - | |
| 182 - if (lazyInit) { | |
| 183 - return (PR_SUCCESS == | |
| 184 - PR_CallOnce(&lockOnce, initSessionCacheLocksLazily)) | |
| 185 - ? SECSuccess | |
| 186 - : SECFailure; | |
| 187 - } | |
| 188 - | |
| 189 - if (SECSuccess == InitSessionCacheLocks()) { | |
| 190 - LocksInitializedEarly = PR_TRUE; | |
| 191 - return SECSuccess; | |
| 192 - } | |
| 193 - | |
| 194 - return SECFailure; | |
| 195 + return (PR_SUCCESS == | |
| 196 + PR_CallOnce(&lockOnce, InitSessionCacheLocks)) | |
| 197 + ? SECSuccess | |
| 198 + : SECFailure; | |
| 199 } | |
| 200 | |
| 201 static void | |
| 202 lock_cache(void) | |
| 203 { | |
| 204 - ssl_InitSessionCacheLocks(PR_TRUE); | |
| 205 + ssl_InitSessionCacheLocks(); | |
| 206 PZ_Lock(cacheLock); | |
| 207 } | |
| 208 | |
| 209 diff --git a/lib/ssl/sslsnce.c b/lib/ssl/sslsnce.c | |
| 210 index da1f93f..e3f749e 100644 | |
| 211 --- a/lib/ssl/sslsnce.c | |
| 212 +++ b/lib/ssl/sslsnce.c | |
| 213 @@ -1344,7 +1344,7 @@ SSL_ConfigServerSessionIDCache(int maxCacheEntries, | |
| 214 PRUint32 ssl3_timeout, | |
| 215 const char *directory) | |
| 216 { | |
| 217 - ssl_InitSessionCacheLocks(PR_FALSE); | |
| 218 + ssl_InitSessionCacheLocks(); | |
| 219 return SSL_ConfigServerSessionIDCacheInstance(&globalCache, | |
| 220 maxCacheEntries, ssl2_timeout
, ssl3_timeout, directory, PR_FALSE); | |
| 221 } | |
| 222 @@ -1458,7 +1458,7 @@ SSL_ConfigServerSessionIDCacheWithOpt( | |
| 223 PRBool enableMPCache) | |
| 224 { | |
| 225 if (!enableMPCache) { | |
| 226 - ssl_InitSessionCacheLocks(PR_FALSE); | |
| 227 + ssl_InitSessionCacheLocks(); | |
| 228 return ssl_ConfigServerSessionIDCacheInstanceWithOpt(&globalCache, | |
| 229 ssl2_timeout, ssl3
_timeout, directory, PR_FALSE, | |
| 230 maxCacheEntries, m
axCertCacheEntries, maxSrvNameCacheEntries); | |
| 231 @@ -1502,7 +1502,7 @@ SSL_InheritMPServerSIDCacheInstance(cacheDesc *cache, cons
t char *envString) | |
| 232 return SECSuccess; /* already done. */ | |
| 233 } | |
| 234 | |
| 235 - ssl_InitSessionCacheLocks(PR_FALSE); | |
| 236 + ssl_InitSessionCacheLocks(); | |
| 237 | |
| 238 ssl_sid_lookup = ServerSessionIDLookup; | |
| 239 ssl_sid_cache = ServerSessionIDCache; | |
| OLD | NEW |