wez             Mon Feb 24 16:40:24 2003 EDT

  Modified files:              
    /php4/ext/standard  file.c 
    /php4/main  php_streams.h 
    /php4/main/streams  cast.c plain_wrapper.c streams.c 
  Log:
  MFB: Bunch of streams related fixes.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.310 php4/ext/standard/file.c:1.311
--- php4/ext/standard/file.c:1.310      Sun Feb 23 22:13:25 2003
+++ php4/ext/standard/file.c    Mon Feb 24 16:40:23 2003
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.310 2003/02/24 03:13:25 iliaa Exp $ */
+/* $Id: file.c,v 1.311 2003/02/24 21:40:23 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2384,7 +2384,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/main/php_streams.h
diff -u php4/main/php_streams.h:1.71 php4/main/php_streams.h:1.72
--- php4/main/php_streams.h:1.71        Mon Feb 17 20:22:21 2003
+++ php4/main/php_streams.h     Mon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_streams.h,v 1.71 2003/02/18 01:22:21 wez Exp $ */
+/* $Id: php_streams.h,v 1.72 2003/02/24 21:40:23 wez Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -405,6 +405,9 @@
 
 /* this flag is used when only the headers from HTTP request are to be fetched */
 #define STREAM_ONLY_GET_HEADERS                512
+
+/* don't apply open_basedir checks */
+#define STREAM_DISABLE_OPEN_BASEDIR    1024
 
 /* Antique - no longer has meaning */
 #define IGNORE_URL_WIN 0
Index: php4/main/streams/cast.c
diff -u php4/main/streams/cast.c:1.3 php4/main/streams/cast.c:1.4
--- php4/main/streams/cast.c:1.3        Wed Feb 19 03:40:19 2003
+++ php4/main/streams/cast.c    Mon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: cast.c,v 1.3 2003/02/19 08:40:19 sniper Exp $ */
+/* $Id: cast.c,v 1.4 2003/02/24 21:40:23 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -208,7 +208,12 @@
                return FAILURE;
 #endif
 
-               if (flags & PHP_STREAM_CAST_TRY_HARD) {
+               if (!php_stream_is_filtered(stream) && 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();
Index: php4/main/streams/plain_wrapper.c
diff -u php4/main/streams/plain_wrapper.c:1.2 php4/main/streams/plain_wrapper.c:1.3
--- php4/main/streams/plain_wrapper.c:1.2       Wed Feb 19 03:40:19 2003
+++ php4/main/streams/plain_wrapper.c   Mon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: plain_wrapper.c,v 1.2 2003/02/19 08:40:19 sniper Exp $ */
+/* $Id: plain_wrapper.c,v 1.3 2003/02/24 21:40:23 wez Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -603,7 +603,7 @@
        DIR *dir = NULL;
        php_stream *stream = NULL;
 
-       if (php_check_open_basedir(path TSRMLS_CC)) {
+       if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(path TSRMLS_CC)) {
                return NULL;
        }
        
@@ -637,7 +637,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;
        }
 
@@ -702,7 +702,7 @@
                }
 
 
-               if (php_check_open_basedir(filename TSRMLS_CC)) {
+               if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(filename TSRMLS_CC)) {
                        return NULL;
                }
 
@@ -722,7 +722,7 @@
        /* Absolute path open */
        if (IS_ABSOLUTE_PATH(filename, filename_length)) {
 
-               if (php_check_open_basedir(filename TSRMLS_CC)) {
+               if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(filename TSRMLS_CC)) {
                        return NULL;
                }
 
@@ -748,7 +748,7 @@
                
                free(cwd);
                
-               if (php_check_open_basedir(trypath TSRMLS_CC)) {
+               if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(trypath TSRMLS_CC)) {
                        return NULL;
                }
                if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) {
@@ -764,7 +764,7 @@
 
        if (!path || (path && !*path)) {
 
-               if (php_check_open_basedir(path TSRMLS_CC)) {
+               if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(path TSRMLS_CC)) {
                        return NULL;
                }
 
@@ -809,7 +809,7 @@
                }
                snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
                
-               if (php_check_open_basedir(trypath TSRMLS_CC)) {
+               if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && 
php_check_open_basedir(trypath TSRMLS_CC)) {
                        stream = NULL;
                        goto stream_done;
                }
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.5 php4/main/streams/streams.c:1.6
--- php4/main/streams/streams.c:1.5     Wed Feb 19 03:40:19 2003
+++ php4/main/streams/streams.c Mon Feb 24 16:40:23 2003
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.5 2003/02/19 08:40:19 sniper Exp $ */
+/* $Id: streams.c,v 1.6 2003/02/24 21:40:23 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -801,6 +801,16 @@
 {
        size_t didwrite = 0, towrite, justwrote;
 
+       /* 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)
@@ -817,8 +827,6 @@
                         * buffered from fifos and sockets */
                        if (stream->ops->seek && (stream->flags & 
PHP_STREAM_FLAG_NO_SEEK) == 0 && !php_stream_is_filtered(stream)) {
                                stream->position += justwrote;
-                               stream->writepos = 0;
-                               stream->readpos = 0;
                        }
                } else {
                        break;
@@ -947,10 +955,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) {
@@ -974,8 +978,6 @@
                }
        }
        
-       /* invalidate the buffer contents */
-       stream->readpos = stream->writepos = 0;
 
        if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
                int ret;
@@ -995,6 +997,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;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to