Skip to content

Commit 8663f16

Browse files
committed
fix for #37158
1 parent 64de59d commit 8663f16

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
20 Apr 2006, PHP 5.1.3RC3
44
- Fixed reading stream filters never notified about EOF. (Mike)
5+
- Fixed bug #37158 (fread behaviour changes after calling
6+
stream_wrapper_register). (Wez)
57
- Fixed bug #37138 (__autoload tries to load callback'ed self and parent).
68
(Dmitry)
79
- Fixed bug #37103 (libmbfl headers not installed). (Jani)

main/streams/php_streams_int.h

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
#define STREAM_DEBUG 0
4848
#define STREAM_WRAPPER_PLAIN_FILES ((php_stream_wrapper*)-1)
49-
extern php_stream_wrapper php_plain_files_wrapper;
5049

5150
#ifndef MAP_FAILED
5251
#define MAP_FAILED ((void *) -1)

main/streams/streams.c

+22-21
Original file line numberDiff line numberDiff line change
@@ -1457,14 +1457,23 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
14571457
return FAILURE;
14581458
}
14591459

1460-
return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, wrapper, sizeof(*wrapper), NULL);
1460+
return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
14611461
}
14621462

14631463
PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
14641464
{
14651465
return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
14661466
}
14671467

1468+
static void clone_wrapper_hash(TSRMLS_D)
1469+
{
1470+
php_stream_wrapper *tmp;
1471+
1472+
ALLOC_HASHTABLE(FG(stream_wrappers));
1473+
zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
1474+
zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp));
1475+
}
1476+
14681477
/* API for registering VOLATILE wrappers */
14691478
PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
14701479
{
@@ -1475,24 +1484,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
14751484
}
14761485

14771486
if (!FG(stream_wrappers)) {
1478-
php_stream_wrapper tmpwrapper;
1479-
1480-
ALLOC_HASHTABLE(FG(stream_wrappers));
1481-
zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
1482-
zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper));
1487+
clone_wrapper_hash(TSRMLS_C);
14831488
}
14841489

1485-
return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, wrapper, sizeof(*wrapper), NULL);
1490+
return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
14861491
}
14871492

14881493
PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
14891494
{
14901495
if (!FG(stream_wrappers)) {
1491-
php_stream_wrapper tmpwrapper;
1492-
1493-
ALLOC_HASHTABLE(FG(stream_wrappers));
1494-
zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
1495-
zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper));
1496+
clone_wrapper_hash(TSRMLS_C);
14961497
}
14971498

14981499
return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol));
@@ -1503,7 +1504,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
15031504
PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC)
15041505
{
15051506
HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
1506-
php_stream_wrapper *wrapper = NULL;
1507+
php_stream_wrapper **wrapperpp = NULL;
15071508
const char *p, *protocol = NULL;
15081509
int n = 0;
15091510

@@ -1529,7 +1530,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
15291530
}
15301531

15311532
if (protocol) {
1532-
if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapper)) {
1533+
if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) {
15331534
char wrapper_name[32];
15341535

15351536
if (n >= sizeof(wrapper_name))
@@ -1539,7 +1540,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
15391540
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?",
15401541
wrapper_name);
15411542

1542-
wrapper = NULL;
1543+
wrapperpp = NULL;
15431544
protocol = NULL;
15441545
}
15451546
}
@@ -1584,14 +1585,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
15841585
if (FG(stream_wrappers)) {
15851586
/* The file:// wrapper may have been disabled/overridden */
15861587

1587-
if (wrapper) {
1588+
if (wrapperpp) {
15881589
/* It was found so go ahead and provide it */
1589-
return wrapper;
1590+
return *wrapperpp;
15901591
}
15911592

15921593
/* Check again, the original check might have not known the protocol name */
1593-
if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapper) == SUCCESS) {
1594-
return wrapper;
1594+
if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapperpp) == SUCCESS) {
1595+
return *wrapperpp;
15951596
}
15961597

15971598
if (options & REPORT_ERRORS) {
@@ -1604,14 +1605,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
16041605
return &php_plain_files_wrapper;
16051606
}
16061607

1607-
if (wrapper && wrapper->is_url && !PG(allow_url_fopen)) {
1608+
if (wrapperpp && (*wrapperpp)->is_url && !PG(allow_url_fopen)) {
16081609
if (options & REPORT_ERRORS) {
16091610
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URL file-access is disabled in the server configuration");
16101611
}
16111612
return NULL;
16121613
}
16131614

1614-
return wrapper;
1615+
return *wrapperpp;
16151616
}
16161617
/* }}} */
16171618

main/streams/userspace.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ PHP_FUNCTION(stream_wrapper_restore)
464464
{
465465
char *protocol;
466466
int protocol_len;
467-
php_stream_wrapper *wrapper = NULL;
467+
php_stream_wrapper **wrapperpp = NULL, *wrapper;
468468
HashTable *global_wrapper_hash;
469469

470470
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
@@ -477,11 +477,14 @@ PHP_FUNCTION(stream_wrapper_restore)
477477
RETURN_TRUE;
478478
}
479479

480-
if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapper) == FAILURE) || !wrapper) {
480+
if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
481481
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
482482
RETURN_FALSE;
483483
}
484484

485+
/* next line might delete the pointer that wrapperpp points at, so deref it now */
486+
wrapper = *wrapperpp;
487+
485488
/* A failure here could be okay given that the protocol might have been merely unregistered */
486489
php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC);
487490

0 commit comments

Comments
 (0)