wez Fri Feb 21 21:43:59 2003 EDT
Added files: (Branch: PHP_4_3)
/php4/ext/standard/tests/file bug22362.phpt
Modified files:
/php4/ext/standard file.c
/php4/ext/standard/tests/file bug21131.phpt
/php4/main php_streams.h streams.c
Log:
Miscellaneous streams fixes, including probable fixes for:
Bug #21131 (fopen with 'a+' and rewind() doesn't work)
Bug #21713 (include remote files leaks temporary files + descriptors on Solaris)
Bug #21185 (move_uploaded_file() does not ignore open_basedir as it should)
Bug #22362 (combinations of fwrite(), fread() and fseek() produce unexpected results)
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.279.2.9 php4/ext/standard/file.c:1.279.2.10
--- php4/ext/standard/file.c:1.279.2.9 Tue Feb 18 10:22:46 2003
+++ php4/ext/standard/file.c Fri Feb 21 21:43:58 2003
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.279.2.9 2003/02/18 15:22:46 moriyoshi Exp $ */
+/* $Id: file.c,v 1.279.2.10 2003/02/22 02:43:58 wez Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -2038,7 +2038,7 @@
int ret = FAILURE;
srcstream = php_stream_open_wrapper(src, "rb",
- ENFORCE_SAFE_MODE | REPORT_ERRORS,
+ STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS,
NULL);
if (!srcstream)
Index: php4/ext/standard/tests/file/bug21131.phpt
diff -u php4/ext/standard/tests/file/bug21131.phpt:1.1.2.1
php4/ext/standard/tests/file/bug21131.phpt:1.1.2.2
--- php4/ext/standard/tests/file/bug21131.phpt:1.1.2.1 Sun Dec 22 13:21:54 2002
+++ php4/ext/standard/tests/file/bug21131.phpt Fri Feb 21 21:43:58 2003
@@ -9,15 +9,10 @@
fclose($fp);
$fp = fopen($filename, "a+");
-var_dump(ftell($fp));
rewind($fp);
-var_dump(ftell($fp));
fpassthru($fp);
fclose($fp);
unlink($filename);
?>
--EXPECT--
-int(6)
-int(0)
foobar
-
Index: php4/main/php_streams.h
diff -u php4/main/php_streams.h:1.61.2.6 php4/main/php_streams.h:1.61.2.7
--- php4/main/php_streams.h:1.61.2.6 Thu Jan 2 08:31:30 2003
+++ php4/main/php_streams.h Fri Feb 21 21:43:58 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_streams.h,v 1.61.2.6 2003/01/02 13:31:30 derick Exp $ */
+/* $Id: php_streams.h,v 1.61.2.7 2003/02/22 02:43:58 wez Exp $ */
#ifndef PHP_STREAMS_H
#define PHP_STREAMS_H
@@ -501,6 +501,11 @@
/* this flag is only used by include/require functions */
#define STREAM_OPEN_FOR_INCLUDE 128
+
+/* 512 skipped for PHP 5 compat */
+
+/* if set, skip open_basedir checks */
+#define STREAM_DISABLE_OPEN_BASEDIR 1024
/* Antique - no longer has meaning */
#define IGNORE_URL_WIN 0
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.125.2.32 php4/main/streams.c:1.125.2.33
--- php4/main/streams.c:1.125.2.32 Wed Feb 19 03:12:25 2003
+++ php4/main/streams.c Fri Feb 21 21:43:58 2003
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.125.2.32 2003/02/19 08:12:25 moriyoshi Exp $ */
+/* $Id: streams.c,v 1.125.2.33 2003/02/22 02:43:58 wez Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -852,6 +852,15 @@
if (buf == NULL || count == 0 || stream->ops->write == NULL)
return 0;
+ /* if we have a seekable stream we need to ensure that data is written at the
+ * current stream->position. This means invalidating the read buffer and then
+ * performing a low-level seek */
+ if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
+ stream->readpos = stream->writepos = 0;
+
+ stream->ops->seek(stream, stream->position, SEEK_SET,
&stream->position TSRMLS_CC);
+ }
+
while (count > 0) {
towrite = count;
if (towrite > stream->chunk_size)
@@ -871,8 +880,6 @@
* buffered from fifos and sockets */
if (stream->ops->seek && (stream->flags &
PHP_STREAM_FLAG_NO_SEEK) == 0) {
stream->position += justwrote;
- stream->writepos = 0;
- stream->readpos = 0;
}
} else {
break;
@@ -907,10 +914,6 @@
PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC)
{
- /* not moving anywhere */
- if ((offset == 0 && whence == SEEK_CUR) || (offset == stream->position &&
whence == SEEK_SET))
- return 0;
-
/* handle the case where we are in the buffer */
if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
switch(whence) {
@@ -933,9 +936,6 @@
break;
}
}
-
- /* invalidate the buffer contents */
- stream->readpos = stream->writepos = 0;
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
int ret;
@@ -954,6 +954,10 @@
if (((stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) || ret == 0) {
if (ret == 0)
stream->eof = 0;
+
+ /* invalidate the buffer contents */
+ stream->readpos = stream->writepos = 0;
+
return ret;
}
/* else the stream has decided that it can't support seeking after all;
@@ -1996,7 +2000,12 @@
return FAILURE;
#endif
- if (flags & PHP_STREAM_CAST_TRY_HARD) {
+ if (!stream->filterhead && stream->ops->cast &&
stream->ops->cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) {
+ if (FAILURE == stream->ops->cast(stream, castas, ret
TSRMLS_CC)) {
+ return FAILURE;
+ }
+ goto exit_success;
+ } else if (flags & PHP_STREAM_CAST_TRY_HARD) {
php_stream *newstream;
newstream = php_stream_fopen_tmpfile();
@@ -2195,7 +2204,7 @@
return php_stream_fopen_with_path_rel(path, mode, PG(include_path),
opened_path, options);
}
- if (php_check_open_basedir(path TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) &&
php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}
Index: php4/ext/standard/tests/file/bug22362.phpt
+++ php4/ext/standard/tests/file/bug22362.phpt
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php