Browse Source

[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>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
3bd0d340f4
1 changed files with 12 additions and 7 deletions
  1. 12
    7
      src/net/tcp/httpconn.c

+ 12
- 7
src/net/tcp/httpconn.c View File

237
 	struct http_scheme *scheme;
237
 	struct http_scheme *scheme;
238
 	struct sockaddr_tcpip server;
238
 	struct sockaddr_tcpip server;
239
 	struct interface *socket;
239
 	struct interface *socket;
240
+	unsigned int port;
240
 	int rc;
241
 	int rc;
241
 
242
 
242
 	/* Identify scheme */
243
 	/* Identify scheme */
248
 	if ( ! uri->host )
249
 	if ( ! uri->host )
249
 		return -EINVAL;
250
 		return -EINVAL;
250
 
251
 
252
+	/* Identify port */
253
+	port = uri_port ( uri, scheme->port );
254
+
251
 	/* Look for a reusable connection in the pool */
255
 	/* Look for a reusable connection in the pool */
252
 	list_for_each_entry ( conn, &http_connection_pool, pool.list ) {
256
 	list_for_each_entry ( conn, &http_connection_pool, pool.list ) {
253
 
257
 
257
 
261
 
258
 		/* Reuse connection, if possible */
262
 		/* Reuse connection, if possible */
259
 		if ( ( scheme == conn->scheme ) &&
263
 		if ( ( scheme == conn->scheme ) &&
260
-		     ( strcmp ( uri->host, conn->uri->host ) == 0 ) ) {
264
+		     ( strcmp ( uri->host, conn->uri->host ) == 0 ) &&
265
+		     ( port == uri_port ( conn->uri, scheme->port ) ) ) {
261
 
266
 
262
 			/* Remove from connection pool, stop timer,
267
 			/* Remove from connection pool, stop timer,
263
 			 * attach to parent interface, and return.
268
 			 * attach to parent interface, and return.
264
 			 */
269
 			 */
265
 			pool_del ( &conn->pool );
270
 			pool_del ( &conn->pool );
266
 			intf_plug_plug ( &conn->xfer, xfer );
271
 			intf_plug_plug ( &conn->xfer, xfer );
267
-			DBGC2 ( conn, "HTTPCONN %p reused %s://%s\n",
268
-				conn, conn->scheme->name, conn->uri->host );
272
+			DBGC2 ( conn, "HTTPCONN %p reused %s://%s:%d\n", conn,
273
+				conn->scheme->name, conn->uri->host, port );
269
 			return 0;
274
 			return 0;
270
 		}
275
 		}
271
 	}
276
 	}
281
 
286
 
282
 	/* Open socket */
287
 	/* Open socket */
283
 	memset ( &server, 0, sizeof ( server ) );
288
 	memset ( &server, 0, sizeof ( server ) );
284
-	server.st_port = htons ( uri_port ( uri, scheme->port ) );
289
+	server.st_port = htons ( port );
285
 	socket = &conn->socket;
290
 	socket = &conn->socket;
286
 	if ( scheme->filter &&
291
 	if ( scheme->filter &&
287
 	     ( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
292
 	     ( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
296
 	ref_put ( &conn->refcnt );
301
 	ref_put ( &conn->refcnt );
297
 
302
 
298
 	DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
303
 	DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
299
-		conn->scheme->name, conn->uri->host, ntohs ( server.st_port ) );
304
+		conn->scheme->name, conn->uri->host, port );
300
 	return 0;
305
 	return 0;
301
 
306
 
302
  err_open:
307
  err_open:
303
  err_filter:
308
  err_filter:
304
-	DBGC2 ( conn, "HTTPCONN %p could not create %s://%s: %s\n",
305
-		conn, conn->scheme->name, conn->uri->host, strerror ( rc ) );
309
+	DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
310
+		conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
306
 	http_conn_close ( conn, rc );
311
 	http_conn_close ( conn, rc );
307
 	ref_put ( &conn->refcnt );
312
 	ref_put ( &conn->refcnt );
308
 	return rc;
313
 	return rc;

Loading…
Cancel
Save