mirror of
https://github.com/php/php-src.git
synced 2026-04-23 07:58:20 +02:00
- Fix read/write mode handling
This commit is contained in:
+13
-4
@@ -912,7 +912,9 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
|
||||
}
|
||||
|
||||
if (phar_open_loaded(fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) {
|
||||
(*pphar)->is_writeable = 1;
|
||||
if (!PHAR_G(readonly)) {
|
||||
(*pphar)->is_writeable = 1;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -926,10 +928,12 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
fp = php_stream_open_wrapper(fname, "r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL);
|
||||
fp = php_stream_open_wrapper(fname, PHAR_G(readonly)?"rb":"r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL);
|
||||
|
||||
if (fp && phar_open_fp(fp, fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) {
|
||||
(*pphar)->is_writeable = 1;
|
||||
if (!PHAR_G(readonly)) {
|
||||
(*pphar)->is_writeable = 1;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1142,6 +1146,11 @@ static php_url* phar_open_url(php_stream_wrapper *wrapper, char *filename, char
|
||||
}
|
||||
#endif
|
||||
if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) {
|
||||
if (PHAR_G(readonly)) {
|
||||
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting");
|
||||
php_url_free(resource);
|
||||
return NULL;
|
||||
}
|
||||
if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, options, NULL TSRMLS_CC) == FAILURE)
|
||||
{
|
||||
php_url_free(resource);
|
||||
@@ -2232,7 +2241,7 @@ static void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stre
|
||||
ssb->sb.st_ctime = phar->max_timestamp;
|
||||
#endif
|
||||
}
|
||||
if (PHAR_G(readonly)) {
|
||||
if (!phar->is_writeable) {
|
||||
ssb->sb.st_mode = (ssb->sb.st_mode & 0555) | (ssb->sb.st_mode & ~0777);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.pha
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECTF--
|
||||
|
||||
Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d
|
||||
Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d
|
||||
|
||||
Warning: include(%screate_new_phar_b.phar.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ include $pname . '/b/c.php';
|
||||
--CLEAN--
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECTF--
|
||||
Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_b.phar.php" cannot opened for writing, disabled by ini setting
|
||||
phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_b.phar.php" in %sopen_for_write_existing_b.php on line %d
|
||||
|
||||
Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
|
||||
|
||||
Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ include $pname . '/b/c.php';
|
||||
--CLEAN--
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECTF--
|
||||
Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_c.phar.php" cannot opened for writing, disabled by ini setting
|
||||
phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_c.phar.php" in %sopen_for_write_existing_c.php on line %d
|
||||
|
||||
Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
|
||||
|
||||
Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ include $pname . '/b/new.php';
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECTF--
|
||||
|
||||
Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_b.phar.php" cannot opened for writing, disabled by ini setting
|
||||
phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line %d
|
||||
Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
|
||||
|
||||
Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ include $pname . '/b/new.php';
|
||||
--CLEAN--
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECTF--
|
||||
Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_c.phar.php" cannot opened for writing, disabled by ini setting
|
||||
phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_c.phar.php" in %sopen_for_write_newfile_c.php on line %d
|
||||
|
||||
Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
|
||||
|
||||
Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ Phar object: iterator & entries
|
||||
<?php if (!extension_loaded("phar")) print "skip"; ?>
|
||||
<?php if (!extension_loaded("spl")) print "skip SPL not available"; ?>
|
||||
--INI--
|
||||
phar.readonly=1
|
||||
phar.require_hash=0
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user