[PHP-CVS] svn: /php/php-src/ branches/PHP_5_3/Zend/zend_alloc.c trunk/Zend/zend_alloc.c

2011-02-07 Thread Pierre Joye
pajoye   Mon, 07 Feb 2011 10:25:34 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=308090

Log:
- null deref fix

Changed paths:
U   php/php-src/branches/PHP_5_3/Zend/zend_alloc.c
U   php/php-src/trunk/Zend/zend_alloc.c

Modified: php/php-src/branches/PHP_5_3/Zend/zend_alloc.c
===
--- php/php-src/branches/PHP_5_3/Zend/zend_alloc.c  2011-02-07 10:17:14 UTC 
(rev 308089)
+++ php/php-src/branches/PHP_5_3/Zend/zend_alloc.c  2011-02-07 10:25:34 UTC 
(rev 308090)
@@ -241,6 +241,10 @@
return NULL;
}
storage = (zend_mm_storage*)malloc(sizeof(zend_mm_storage));
+   if (storage == NULL) {
+   HeapDestroy(heap);
+   return NULL;
+   }
storage-data = (void*) heap;
return storage;
 }
@@ -1066,7 +1070,13 @@
storage-handlers = handlers;

heap = malloc(sizeof(struct _zend_mm_heap));
-
+   if (heap == NULL) {
+   fprintf(stderr, Cannot allocate heap for zend_mm storage 
[%s]\n, handlers-name);
+#ifdef PHP_WIN32
+   fflush(stderr);
+#endif
+   exit(255);
+   }
heap-storage = storage;
heap-block_size = block_size;
heap-compact_size = 0;

Modified: php/php-src/trunk/Zend/zend_alloc.c
===
--- php/php-src/trunk/Zend/zend_alloc.c 2011-02-07 10:17:14 UTC (rev 308089)
+++ php/php-src/trunk/Zend/zend_alloc.c 2011-02-07 10:25:34 UTC (rev 308090)
@@ -241,6 +241,10 @@
return NULL;
}
storage = (zend_mm_storage*)malloc(sizeof(zend_mm_storage));
+   if (storage == NULL) {
+   HeapDestroy(heap);
+   return NULL;
+   }
storage-data = (void*) heap;
return storage;
 }
@@ -1088,7 +1092,13 @@
storage-handlers = handlers;

heap = malloc(sizeof(struct _zend_mm_heap));
-
+   if (heap == NULL) {
+   fprintf(stderr, Cannot allocate heap for zend_mm storage 
[%s]\n, handlers-name);
+#ifdef PHP_WIN32
+   fflush(stderr);
+#endif
+   exit(255);
+   }
heap-storage = storage;
heap-block_size = block_size;
heap-compact_size = 0;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/ branches/PHP_5_3/Zend/zend_alloc.c trunk/Zend/zend_alloc.c

2010-02-01 Thread Pierre Joye
pajoye   Mon, 01 Feb 2010 14:56:51 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=294307

Log:
- 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)

Changed paths:
U   php/php-src/branches/PHP_5_3/Zend/zend_alloc.c
U   php/php-src/trunk/Zend/zend_alloc.c

Modified: php/php-src/branches/PHP_5_3/Zend/zend_alloc.c
===
--- php/php-src/branches/PHP_5_3/Zend/zend_alloc.c  2010-02-01 14:09:23 UTC 
(rev 294306)
+++ php/php-src/branches/PHP_5_3/Zend/zend_alloc.c  2010-02-01 14:56:51 UTC 
(rev 294307)
@@ -944,15 +944,27 @@
 #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;
+   int has_context = 0;

-   if (CryptAcquireContext(hCryptProv, NULL, NULL, PROV_RSA_FULL, 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 @@
i++;
}
if (i == size) {
-   return;
+   return;
}
   }
} while (0);
@@ -990,6 +1002,7 @@
t = buf[i++]  1;
 }
 }
+/* }}} */
 #endif

 /* Notes:

Modified: php/php-src/trunk/Zend/zend_alloc.c
===
--- php/php-src/trunk/Zend/zend_alloc.c 2010-02-01 14:09:23 UTC (rev 294306)
+++ php/php-src/trunk/Zend/zend_alloc.c 2010-02-01 14:56:51 UTC (rev 294307)
@@ -979,8 +979,20 @@

 #ifdef ZEND_WIN32
HCRYPTPROV   hCryptProv;
+   int has_context = 0;

-   if (CryptAcquireContext(hCryptProv, NULL, NULL, PROV_RSA_FULL, 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);
@@ -989,7 +1001,7 @@
i++;
}
if (i == size) {
-   return;
+   return;
}
   }
} while (0);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php