iliaa                                    Tue, 11 May 2010 14:31:00 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299244

Log:
Removed double allocation of buffer inside openssl_random_pseudo_bytes() and 
cleanup code

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/openssl/openssl.c
    U   php/php-src/trunk/ext/openssl/openssl.c

Modified: php/php-src/branches/PHP_5_3/ext/openssl/openssl.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/openssl/openssl.c  2010-05-11 14:12:30 UTC 
(rev 299243)
+++ php/php-src/branches/PHP_5_3/ext/openssl/openssl.c  2010-05-11 14:31:00 UTC 
(rev 299244)
@@ -4785,27 +4785,23 @@
                ZVAL_BOOL(zstrong_result_returned, 0);
        }

-       buffer = emalloc(buffer_length);
+       buffer = emalloc(buffer_length + 1);

-       if (!buffer) {
-               RETURN_FALSE;
-       }
-
 #ifdef WINDOWS
         RAND_screen();
 #endif

        if ((strong_result = RAND_pseudo_bytes(buffer, buffer_length)) < 0) {
-               RETVAL_FALSE;
-       } else {
-               RETVAL_STRINGL((char *)buffer, buffer_length, 1);
+               efree(buffer);
+               RETURN_FALSE;
+       }

-               if (zstrong_result_returned) {
-                       ZVAL_BOOL(zstrong_result_returned, strong_result);
-               }
+       buffer[buffer_length] = 0;
+       RETVAL_STRINGL((char *)buffer, buffer_length, 0);

+       if (zstrong_result_returned) {
+               ZVAL_BOOL(zstrong_result_returned, strong_result);
        }
-       efree(buffer);
 }
 /* }}} */


Modified: php/php-src/trunk/ext/openssl/openssl.c
===================================================================
--- php/php-src/trunk/ext/openssl/openssl.c     2010-05-11 14:12:30 UTC (rev 
299243)
+++ php/php-src/trunk/ext/openssl/openssl.c     2010-05-11 14:31:00 UTC (rev 
299244)
@@ -4780,27 +4780,23 @@
                ZVAL_BOOL(zstrong_result_returned, 0);
        }

-       buffer = emalloc(buffer_length);
+       buffer = emalloc(buffer_length + 1);

-       if (!buffer) {
-               RETURN_FALSE;
-       }
-
 #ifdef WINDOWS
         RAND_screen();
 #endif

        if ((strong_result = RAND_pseudo_bytes(buffer, buffer_length)) < 0) {
-               RETVAL_FALSE;
-       } else {
-               RETVAL_STRINGL((char *)buffer, buffer_length, 1);
+               efree(buffer);
+               RETURN_FALSE;
+       }

-               if (zstrong_result_returned) {
-                       ZVAL_BOOL(zstrong_result_returned, strong_result);
-               }
+       buffer[buffer_length] = 0;
+       RETVAL_STRINGL((char *)buffer, buffer_length, 0);

+       if (zstrong_result_returned) {
+               ZVAL_BOOL(zstrong_result_returned, strong_result);
        }
-       efree(buffer);
 }
 /* }}} */


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

Reply via email to