@@ -46,7 +46,7 @@ static void php_bin_to_hex(char *old, const zend_long old_len, char *hex)
46
46
}
47
47
48
48
// Copy/pasted from mcrypt.c
49
- static int php_random_bytes (char * bytes , zend_long size )
49
+ static int php_random_bytes (zend_string * bytes , zend_long size )
50
50
{
51
51
int n = 0 ;
52
52
@@ -90,7 +90,7 @@ Return an arbitrary length of pseudo-random bytes as binary string */
90
90
PHP_FUNCTION (random_bytes )
91
91
{
92
92
zend_long size ;
93
- char * bytes ;
93
+ zend_string * bytes ;
94
94
95
95
if (zend_parse_parameters (ZEND_NUM_ARGS (), "l" , & size ) == FAILURE ) {
96
96
return ;
@@ -101,16 +101,16 @@ PHP_FUNCTION(random_bytes)
101
101
RETURN_FALSE ;
102
102
}
103
103
104
- bytes = ecalloc (size + 1 , 1 );
104
+ bytes = zend_string_alloc (size + 1 , 0 );
105
105
106
106
if (php_random_bytes (bytes , size ) == FAILURE ) {
107
- efree (bytes );
107
+ zend_string_release (bytes );
108
108
return ;
109
109
}
110
110
111
111
RETVAL_STRINGL (bytes , size );
112
112
113
- efree (bytes );
113
+ zend_string_release (bytes );
114
114
}
115
115
/* }}} */
116
116
@@ -119,8 +119,8 @@ Return an arbitrary length of pseudo-random bytes as hexadecimal string */
119
119
PHP_FUNCTION (random_hex )
120
120
{
121
121
zend_long size ;
122
- char * bytes ;
123
- char * hex ;
122
+ zend_string * bytes ;
123
+ zend_string * hex ;
124
124
125
125
if (zend_parse_parameters (ZEND_NUM_ARGS (), "l" , & size ) == FAILURE ) {
126
126
return ;
@@ -132,21 +132,21 @@ PHP_FUNCTION(random_hex)
132
132
}
133
133
134
134
// @todo should we half the size for hex? How for odd num of chars?
135
- bytes = ecalloc (size + 1 , 1 );
135
+ bytes = zend_string_alloc (size + 1 , 0 );
136
136
137
137
if (php_random_bytes (bytes , size ) == FAILURE ) {
138
- efree (bytes );
138
+ zend_string_release (bytes );
139
139
return ;
140
140
}
141
141
142
142
int hex_size = size * 2 ;
143
- hex = ecalloc (hex_size + 1 , 1 );
143
+ hex = zend_string_alloc (hex_size + 1 , 0 );
144
144
php_bin_to_hex (bytes , hex_size , hex );
145
145
146
146
RETVAL_STRINGL (hex , hex_size );
147
147
148
- efree (bytes );
149
- efree (hex );
148
+ zend_string_release (bytes );
149
+ zend_string_release (hex );
150
150
}
151
151
/* }}} */
152
152
0 commit comments