Skip to content

Commit cbfb63c

Browse files
author
Ilia Alshanetsky
committed
Fixed possible crashes in streams code
1 parent ba3e315 commit cbfb63c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

ext/standard/info.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
471471
HashTable *url_stream_wrappers_hash;
472472
char *stream_protocol, *stream_protocols_buf = NULL;
473473
int stream_protocol_len, stream_protocols_buf_len = 0;
474+
ulong num_key;
474475

475476
if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
476477
for (zend_hash_internal_pointer_reset(url_stream_wrappers_hash);
477-
zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL) == HASH_KEY_IS_STRING;
478+
zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING;
478479
zend_hash_move_forward(url_stream_wrappers_hash)) {
479480
stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1);
480481
memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len);

ext/standard/streamsfuncs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ PHP_FUNCTION(stream_get_transports)
353353
HashTable *stream_xport_hash;
354354
char *stream_xport;
355355
int stream_xport_len;
356+
ulong num_key;
356357

357358
if (ZEND_NUM_ARGS() != 0) {
358359
WRONG_PARAM_COUNT;
@@ -363,7 +364,7 @@ PHP_FUNCTION(stream_get_transports)
363364
zend_hash_internal_pointer_reset(stream_xport_hash);
364365
while (zend_hash_get_current_key_ex(stream_xport_hash,
365366
&stream_xport, &stream_xport_len,
366-
NULL, 0, NULL) == HASH_KEY_IS_STRING) {
367+
&num_key, 0, NULL) == HASH_KEY_IS_STRING) {
367368
add_next_index_stringl(return_value, stream_xport, stream_xport_len, 1);
368369
zend_hash_move_forward(stream_xport_hash);
369370
}
@@ -380,6 +381,7 @@ PHP_FUNCTION(stream_get_wrappers)
380381
HashTable *url_stream_wrappers_hash;
381382
char *stream_protocol;
382383
int key_flags, stream_protocol_len = 0;
384+
ulong num_key;
383385

384386
if (ZEND_NUM_ARGS() != 0) {
385387
WRONG_PARAM_COUNT;
@@ -388,7 +390,7 @@ PHP_FUNCTION(stream_get_wrappers)
388390
if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
389391
array_init(return_value);
390392
for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash);
391-
(key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT;
393+
(key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT;
392394
zend_hash_move_forward(url_stream_wrappers_hash)) {
393395
if (key_flags == HASH_KEY_IS_STRING) {
394396
add_next_index_stringl(return_value, stream_protocol, stream_protocol_len, 1);
@@ -640,16 +642,17 @@ static int parse_context_options(php_stream_context *context, zval *options)
640642
char *wkey, *okey;
641643
int wkey_len, okey_len;
642644
int ret = SUCCESS;
645+
ulong num_key;
643646

644647
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos);
645648
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(options), (void**)&wval, &pos)) {
646-
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &wkey_len, NULL, 0, &pos)
649+
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &wkey_len, &num_key, 0, &pos)
647650
&& Z_TYPE_PP(wval) == IS_ARRAY) {
648651

649652
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(wval), &opos);
650653
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)&oval, &opos)) {
651654

652-
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, NULL, 0, &opos)) {
655+
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, &num_key, 0, &opos)) {
653656
php_stream_context_set_option(context, wkey, okey, *oval);
654657
}
655658
zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), &opos);

ext/standard/user_filters.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ PHP_FUNCTION(stream_get_filters)
427427
char *filter_name;
428428
int key_flags, filter_name_len = 0;
429429
HashTable *filters_hash;
430+
ulong num_key;
430431

431432
if (ZEND_NUM_ARGS() != 0) {
432433
WRONG_PARAM_COUNT;
@@ -438,7 +439,7 @@ PHP_FUNCTION(stream_get_filters)
438439

439440
if (filters_hash) {
440441
for(zend_hash_internal_pointer_reset(filters_hash);
441-
(key_flags = zend_hash_get_current_key_ex(filters_hash, &filter_name, &filter_name_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT;
442+
(key_flags = zend_hash_get_current_key_ex(filters_hash, &filter_name, &filter_name_len, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT;
442443
zend_hash_move_forward(filters_hash))
443444
if (key_flags == HASH_KEY_IS_STRING)
444445
add_next_index_stringl(return_value, filter_name, filter_name_len, 1);

0 commit comments

Comments
 (0)