summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2010-02-01 14:56:51 +0000
committerPierre Joye <pajoye@php.net>2010-02-01 14:56:51 +0000
commitd839e3b9a40586b11560c887805f3dc71183fb81 (patch)
treef79fdc0719282ee3875673e41fea61df33d56ad3
parentcca05f1403dca5db3f090850d8623cb7f36cd188 (diff)
downloadphp-git-d839e3b9a40586b11560c887805f3dc71183fb81.tar.gz
- try again to get a crypto context when the key container did not exist (which is likely to be the case, on a 1st call)
-rw-r--r--Zend/zend_alloc.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 8c7397a722..e71456ab37 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -944,15 +944,27 @@ static void zend_mm_free_cache(zend_mm_heap *heap)
#endif
#if ZEND_MM_HEAP_PROTECTION || ZEND_MM_COOKIES
-static void zend_mm_random(unsigned char *buf, size_t size)
+static void zend_mm_random(unsigned char *buf, size_t size) /* {{{ */
{
size_t i = 0;
unsigned char t;
#ifdef ZEND_WIN32
HCRYPTPROV hCryptProv;
-
- if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) {
+ int has_context = 0;
+
+ if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) {
+ /* Could mean that the key container does not exist, let try
+ again by asking for a new one */
+ if (GetLastError() == NTE_BAD_KEYSET) {
+ if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
+ has_context = 1;
+ }
+ }
+ } else {
+ has_context = 1;
+ }
+ if (has_context) {
do {
BOOL ret = CryptGenRandom(hCryptProv, size, buf);
CryptReleaseContext(hCryptProv, 0);
@@ -961,7 +973,7 @@ static void zend_mm_random(unsigned char *buf, size_t size)
i++;
}
if (i == size) {
- return;
+ return;
}
}
} while (0);
@@ -990,6 +1002,7 @@ static void zend_mm_random(unsigned char *buf, size_t size)
t = buf[i++] << 1;
}
}
+/* }}} */
#endif
/* Notes: