]> granicus.if.org Git - php/commitdiff
- Fixed bug #53198 (changing INI setting "from" with ini_set did not have any
authorGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 29 Oct 2010 15:29:15 +0000 (15:29 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 29 Oct 2010 15:29:15 +0000 (15:29 +0000)
  effect)
#Made "from" a proper INI setting and bound it to a global variable.
#Previously, it was simply read from the hash table with the parsed ini file
#by using cfg_get_string (I wonder why this mechanism still exists...)

ext/standard/file.c
ext/standard/file.h
ext/standard/ftp_fopen_wrapper.c
ext/standard/http_fopen_wrapper.c
ext/standard/tests/http/bug53198.phpt [new file with mode: 0644]

index 2d7e581bbc21e6c58a5b7e224c392585772497b5..95106a8af8547cdd09294e42e46c32ca80c4bdb7 100644 (file)
@@ -169,6 +169,7 @@ static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC)
 
 PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals)
+       STD_PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, OnUpdateString, from_address, php_file_globals, file_globals)
        STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals)
        STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateLong, auto_detect_line_endings, php_file_globals, file_globals)
 PHP_INI_END()
index cdf356f352c34a2f205baf32b6d2dbf5dcbfd7e7..2284a28b9646069be249d03a96a8789ec00f069d 100644 (file)
@@ -118,7 +118,8 @@ typedef struct {
        size_t def_chunk_size;
        long auto_detect_line_endings;
        long default_socket_timeout;
-       char *user_agent;
+       char *user_agent; /* for the http wrapper */
+       char *from_address; /* for the ftp and http wrappers */
        char *user_stream_current_filename; /* for simple recursion protection */
        php_stream_context *default_context;
        HashTable *stream_wrappers;                     /* per-request copy of url_stream_wrappers_hash */
index d4a4896aa1a35979507aeb56414e05c66deb1f14..6b858b6aed686312dd97fcb715349ddf5b452617 100644 (file)
@@ -116,7 +116,6 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, char *path
        php_stream *stream = NULL, *reuseid = NULL;
        php_url *resource = NULL;
        int result, use_ssl, use_ssl_on_data = 0, tmp_len;
-       char *scratch;
        char tmp_line[512];
        char *transport;
        int transport_len;
@@ -250,8 +249,8 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, char *path
                } else {
                        /* if the user has configured who they are,
                           send that as the password */
-                       if (cfg_get_string("from", &scratch) == SUCCESS) {
-                               php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", scratch);
+                       if (FG(from_address)) {
+                               php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", FG(from_address));
                        } else {
                                php_stream_write_string(stream, "PASS anonymous\r\n");
                        }
index 7d238d65acfd4063e89724f1c975bd8e487b750e..301a3e1fcfb57a95165a0de7f643cd7fc6d6bb48 100644 (file)
@@ -443,8 +443,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
        }
 
        /* if the user has configured who they are, send a From: line */
-       if (((have_header & HTTP_HEADER_FROM) == 0) && cfg_get_string("from", &tmp) == SUCCESS) {
-               if (snprintf(scratch, scratch_len, "From: %s\r\n", tmp) > 0)
+       if (((have_header & HTTP_HEADER_FROM) == 0) && FG(from_address)) {
+               if (snprintf(scratch, scratch_len, "From: %s\r\n", FG(from_address)) > 0)
                        php_stream_write(stream, scratch, strlen(scratch));
        }
 
diff --git a/ext/standard/tests/http/bug53198.phpt b/ext/standard/tests/http/bug53198.phpt
new file mode 100644 (file)
index 0000000..fe26bc9
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--\r
+Bug #53198 (From: header cannot be changed with ini_set)\r
+--SKIPIF--\r
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>\r
+--INI--\r
+from=teste@teste.pt\r
+--FILE--\r
+<?php\r
+require 'server.inc';\r
+\r
+function do_test() {\r
+\r
+       $responses = array(\r
+               "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",\r
+       );\r
+\r
+       $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);\r
+\r
+       foreach($responses as $r) {\r
+\r
+               $fd = fopen('http://127.0.0.1:12342/', 'rb', false);\r
+\r
+               fseek($output, 0, SEEK_SET);\r
+               var_dump(stream_get_contents($output));\r
+               fseek($output, 0, SEEK_SET);\r
+       }\r
+\r
+       http_server_kill($pid);\r
+\r
+}\r
+\r
+echo "-- Test: leave default --\n";\r
+\r
+do_test();\r
+\r
+echo "-- Test: after ini_set --\n";\r
+\r
+ini_set('from', 'junk@junk.com');\r
+\r
+do_test();\r
+\r
+?>\r
+--EXPECT--\r
+-- Test: leave default --\r
+string(63) "GET / HTTP/1.0\r
+From: teste@teste.pt\r
+Host: 127.0.0.1:12342\r
+\r
+"\r
+-- Test: after ini_set --\r
+string(62) "GET / HTTP/1.0\r
+From: junk@junk.com\r
+Host: 127.0.0.1:12342\r
+\r
+"\r
+\r