]> granicus.if.org Git - php/commitdiff
Fix bug #62524, only follow redirects in file streams for 3xx HTTP statuses
authorStanislav Malyshev <stas@php.net>
Tue, 29 Jan 2013 08:24:23 +0000 (00:24 -0800)
committerStanislav Malyshev <stas@php.net>
Tue, 29 Jan 2013 08:27:35 +0000 (00:27 -0800)
NEWS
ext/standard/http_fopen_wrapper.c

diff --git a/NEWS b/NEWS
index 21892b7eb17b678676005500e82b267aa027fc21..28f151febb22328e0498d2692fff5764c4df95b3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ PHP                                                                        NEWS
   . Fixed bug #63882 (zend_std_compare_objects crash on recursion). (Dmitry)
   . Fixed bug #63462 (Magic methods called twice for unset protected 
     properties). (Stas)
+  . Fixed bug #62524 (fopen follows redirects for non-3xx statuses). 
+    (Wes Mason) 
   . Support BITMAPV5HEADER in getimagesize(). (AsamK, Lars)
 
 - Date:
index 85a61167aa10ddcb203d1665d4e033e7a17a1d71..870f904e9c3e3a62ab16f0cc28129fa5476b0bf0 100644 (file)
@@ -113,6 +113,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
        int redirected = ((flags & HTTP_WRAPPER_REDIRECTED) != 0);
        int follow_location = 1;
        php_stream_filter *transfer_encoding = NULL;
+       int response_code;
 
        tmp_line[0] = '\0';
 
@@ -657,7 +658,6 @@ finish:
 
                if (php_stream_get_line(stream, tmp_line, sizeof(tmp_line) - 1, &tmp_line_len) != NULL) {
                        zval *http_response;
-                       int response_code;
 
                        if (tmp_line_len > 9) {
                                response_code = atoi(tmp_line + 9);
@@ -731,7 +731,9 @@ finish:
                        http_header_line[http_header_line_length] = '\0';
 
                        if (!strncasecmp(http_header_line, "Location: ", 10)) {
-                               if (context && php_stream_context_get_option(context, "http", "follow_location", &tmpzval) == SUCCESS) {
+                               /* we only care about Location for 300, 301, 302, 303 and 307 */
+                               /* see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1 */
+                               if ((response_code >= 300 && response_code < 304 || 307 == response_code) && context && php_stream_context_get_option(context, "http", "follow_location", &tmpzval) == SUCCESS) {
                                        SEPARATE_ZVAL(tmpzval);
                                        convert_to_long_ex(tmpzval);
                                        follow_location = Z_LVAL_PP(tmpzval);