int ret = FAILURE;
srcstream = php_stream_open_wrapper(src, "rb",
- ENFORCE_SAFE_MODE | REPORT_ERRORS,
+ STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS,
NULL);
if (!srcstream) {
/* 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
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();
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;
}
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;
}
}
- if (php_check_open_basedir(filename TSRMLS_CC)) {
+ if ((options & STREAM_DISABLE_OPEN_BASEDIR == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
return NULL;
}
/* 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;
}
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) {
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;
}
}
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;
}
{
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)
* 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;
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) {
}
}
- /* invalidate the buffer contents */
- stream->readpos = stream->writepos = 0;
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
int ret;
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;