Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void http_context_headers(php_stream_context* context,
static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, php_stream_context *context, int *use_proxy)
{
php_stream *stream;
zval *proxy_host, *proxy_port, *tmp;
zval *proxy_host, *proxy_port, *tmp, ssl_proxy_peer_name;
char *host;
char *name;
char *protocol;
Expand Down Expand Up @@ -241,6 +241,13 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph
if (stream && *use_proxy && use_ssl) {
smart_str soap_headers = {0};

/* Set peer_name or name verification will try to use the proxy server name */
if (!context || (tmp = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) {
ZVAL_STRING(&ssl_proxy_peer_name, phpurl->host);
php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name);
zval_ptr_dtor(&ssl_proxy_peer_name);
}

smart_str_append_const(&soap_headers, "CONNECT ");
smart_str_appends(&soap_headers, phpurl->host);
smart_str_appendc(&soap_headers, ':');
Expand Down
2 changes: 2 additions & 0 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,8 @@ PHP_METHOD(SoapClient, SoapClient)
Z_TYPE_P(tmp) == IS_RESOURCE) {
context = php_stream_context_from_zval(tmp, 1);
Z_ADDREF_P(tmp);
} else {
context = php_stream_context_alloc();
Copy link
Member

@nikic nikic Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the condition includes !context || instead of context &&, is this part of the change still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, the stream in http_connect is created without a context, and the call to php_stream_context_set_option segfaults with a null pointer dereference.

}

if ((tmp = zend_hash_str_find(ht, "location", sizeof("location")-1)) != NULL &&
Expand Down
46 changes: 46 additions & 0 deletions ext/soap/tests/bug69137.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
SOAP Bug #69137 - Peer verification fails when using a proxy with SoapClient
--SKIPIF--
<?php
require_once('skipif.inc');
if (getenv("SKIP_ONLINE_TESTS")) { die("skip test requiring internet connection"); }
if (!getenv('http_proxy')) { die("skip test unless an HTTP/HTTPS proxy server is specified in http_proxy environment variable"); }
?>
--INI--
soap.wsdl_cache_enabled=1
--FILE--
<?php

class IpLookup
{
public $licenseKey;
public $ipAddress;
}

list ($proxyHost, $proxyPort) = explode(':', str_replace('http://', '', $_ENV['http_proxy']));

// Prime the WSDL cache because that request sets peer_name on the HTTP context
// and masks the SOAP bug.
$testServiceWsdl = 'https://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl';
$client = new SoapClient($testServiceWsdl);
unset($client);

$parameters = [
'proxy_host' => $proxyHost,
'proxy_port' => $proxyPort,
'trace' => 1,
];
$client = new SoapClient($testServiceWsdl, $parameters);

$lookup = new IpLookup();
$lookup->licenseKey = 0;
$lookup->ipAddress = '72.52.91.14';

$result = $client->ResolveIP($lookup);

if ($result && is_object($result) && $result->ResolveIPResult && is_object($result->ResolveIPResult)) {
print "successful lookup";
}
?>
--EXPECT--
successful lookup