Skip to content

Commit 5382e15

Browse files
committed
Fix bug #62524, only follow redirects in file streams for 3xx HTTP statuses
1 parent 3e6d633 commit 5382e15

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515
. Fixed bug #63882 (zend_std_compare_objects crash on recursion). (Dmitry)
1616
. Fixed bug #63462 (Magic methods called twice for unset protected
1717
properties). (Stas)
18+
. Fixed bug #62524 (fopen follows redirects for non-3xx statuses).
19+
(Wes Mason)
1820
. Support BITMAPV5HEADER in getimagesize(). (AsamK, Lars)
1921

2022
- Date:

ext/standard/http_fopen_wrapper.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
113113
int redirected = ((flags & HTTP_WRAPPER_REDIRECTED) != 0);
114114
int follow_location = 1;
115115
php_stream_filter *transfer_encoding = NULL;
116+
int response_code;
116117

117118
tmp_line[0] = '\0';
118119

@@ -657,7 +658,6 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
657658

658659
if (php_stream_get_line(stream, tmp_line, sizeof(tmp_line) - 1, &tmp_line_len) != NULL) {
659660
zval *http_response;
660-
int response_code;
661661

662662
if (tmp_line_len > 9) {
663663
response_code = atoi(tmp_line + 9);
@@ -731,7 +731,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
731731
http_header_line[http_header_line_length] = '\0';
732732

733733
if (!strncasecmp(http_header_line, "Location: ", 10)) {
734-
if (context && php_stream_context_get_option(context, "http", "follow_location", &tmpzval) == SUCCESS) {
734+
/* we only care about Location for 300, 301, 302, 303 and 307 */
735+
/* see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1 */
736+
if ((response_code >= 300 && response_code < 304 || 307 == response_code) && context && php_stream_context_get_option(context, "http", "follow_location", &tmpzval) == SUCCESS) {
735737
SEPARATE_ZVAL(tmpzval);
736738
convert_to_long_ex(tmpzval);
737739
follow_location = Z_LVAL_PP(tmpzval);

0 commit comments

Comments
 (0)