--- embedaddon/php/main/streams/streams.c 2013/10/14 08:02:43 1.1.1.4 +++ embedaddon/php/main/streams/streams.c 2014/06/15 20:04:01 1.1.1.5 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.1.1.4 2013/10/14 08:02:43 misho Exp $ */ +/* $Id: streams.c,v 1.1.1.5 2014/06/15 20:04:01 misho Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -736,6 +736,10 @@ PHPAPI size_t _php_stream_read(php_stream *stream, cha if (!stream->readfilters.head && (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1)) { toread = stream->ops->read(stream, buf, size TSRMLS_CC); + if (toread == (size_t) -1) { + /* e.g. underlying read(2) returned -1 */ + break; + } } else { php_stream_fill_read_buffer(stream, size TSRMLS_CC); @@ -1401,11 +1405,16 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); if (p) { - PHPWRITE(p, mapped); + do { + /* output functions return int, so pass in int max */ + if (0 < (b = PHPWRITE(p, MIN(mapped - bcount, INT_MAX)))) { + bcount += b; + } + } while (b > 0 && mapped > bcount); php_stream_mmap_unmap_ex(stream, mapped); - return mapped; + return bcount; } } @@ -1920,36 +1929,40 @@ PHPAPI int _php_stream_stat_path(char *path, int flags char *path_to_open = path; int ret; - /* Try to hit the cache first */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { - memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); - return 0; + if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + /* Try to hit the cache first */ + if (flags & PHP_STREAM_URL_STAT_LINK) { + if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { + memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); + return 0; + } + } else { + if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { + memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); + return 0; + } } - } else { - if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { - memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); - return 0; - } } wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC); if (wrapper && wrapper->wops->url_stat) { ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); if (ret == 0) { - /* Drop into cache */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile)) { - efree(BG(CurrentLStatFile)); + if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + /* Drop into cache */ + if (flags & PHP_STREAM_URL_STAT_LINK) { + if (BG(CurrentLStatFile)) { + efree(BG(CurrentLStatFile)); + } + BG(CurrentLStatFile) = estrdup(path); + memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); + } else { + if (BG(CurrentStatFile)) { + efree(BG(CurrentStatFile)); + } + BG(CurrentStatFile) = estrdup(path); + memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); } - BG(CurrentLStatFile) = estrdup(path); - memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); - } else { - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); - } - BG(CurrentStatFile) = estrdup(path); - memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); } } return ret;