mirror of https://github.com/ipxe/ipxe.git
[http] Verify server port when reusing a pooled connection
Reported-by: Allen <allen@gtf.org> Reported-by: Andreas Hammarskjöld <junior@2PintSoftware.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/41/head
parent
0a4805bf94
commit
3bd0d340f4
|
@ -237,6 +237,7 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||||
struct http_scheme *scheme;
|
struct http_scheme *scheme;
|
||||||
struct sockaddr_tcpip server;
|
struct sockaddr_tcpip server;
|
||||||
struct interface *socket;
|
struct interface *socket;
|
||||||
|
unsigned int port;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Identify scheme */
|
/* Identify scheme */
|
||||||
|
@ -248,6 +249,9 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||||
if ( ! uri->host )
|
if ( ! uri->host )
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* Identify port */
|
||||||
|
port = uri_port ( uri, scheme->port );
|
||||||
|
|
||||||
/* Look for a reusable connection in the pool */
|
/* Look for a reusable connection in the pool */
|
||||||
list_for_each_entry ( conn, &http_connection_pool, pool.list ) {
|
list_for_each_entry ( conn, &http_connection_pool, pool.list ) {
|
||||||
|
|
||||||
|
@ -257,15 +261,16 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||||
|
|
||||||
/* Reuse connection, if possible */
|
/* Reuse connection, if possible */
|
||||||
if ( ( scheme == conn->scheme ) &&
|
if ( ( scheme == conn->scheme ) &&
|
||||||
( strcmp ( uri->host, conn->uri->host ) == 0 ) ) {
|
( strcmp ( uri->host, conn->uri->host ) == 0 ) &&
|
||||||
|
( port == uri_port ( conn->uri, scheme->port ) ) ) {
|
||||||
|
|
||||||
/* Remove from connection pool, stop timer,
|
/* Remove from connection pool, stop timer,
|
||||||
* attach to parent interface, and return.
|
* attach to parent interface, and return.
|
||||||
*/
|
*/
|
||||||
pool_del ( &conn->pool );
|
pool_del ( &conn->pool );
|
||||||
intf_plug_plug ( &conn->xfer, xfer );
|
intf_plug_plug ( &conn->xfer, xfer );
|
||||||
DBGC2 ( conn, "HTTPCONN %p reused %s://%s\n",
|
DBGC2 ( conn, "HTTPCONN %p reused %s://%s:%d\n", conn,
|
||||||
conn, conn->scheme->name, conn->uri->host );
|
conn->scheme->name, conn->uri->host, port );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +286,7 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||||
|
|
||||||
/* Open socket */
|
/* Open socket */
|
||||||
memset ( &server, 0, sizeof ( server ) );
|
memset ( &server, 0, sizeof ( server ) );
|
||||||
server.st_port = htons ( uri_port ( uri, scheme->port ) );
|
server.st_port = htons ( port );
|
||||||
socket = &conn->socket;
|
socket = &conn->socket;
|
||||||
if ( scheme->filter &&
|
if ( scheme->filter &&
|
||||||
( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
|
( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
|
||||||
|
@ -296,13 +301,13 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||||
ref_put ( &conn->refcnt );
|
ref_put ( &conn->refcnt );
|
||||||
|
|
||||||
DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
|
DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
|
||||||
conn->scheme->name, conn->uri->host, ntohs ( server.st_port ) );
|
conn->scheme->name, conn->uri->host, port );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_open:
|
err_open:
|
||||||
err_filter:
|
err_filter:
|
||||||
DBGC2 ( conn, "HTTPCONN %p could not create %s://%s: %s\n",
|
DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
|
||||||
conn, conn->scheme->name, conn->uri->host, strerror ( rc ) );
|
conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
|
||||||
http_conn_close ( conn, rc );
|
http_conn_close ( conn, rc );
|
||||||
ref_put ( &conn->refcnt );
|
ref_put ( &conn->refcnt );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue