From 24d4a724de16ad797ec19cc8fe3fddf67e011e6c Mon Sep 17 00:00:00 2001 From: bluhm Date: Wed, 29 Apr 2015 08:41:24 +0000 Subject: [PATCH] When the HTTP client did close the connection while relayd was still parsig the HTTP header, the session was never destroyed. This resulted in a file descriptor leak. Add a check wether the protocol knows how much data to expect. If relayd is reading unlimited data or is expecting nothing to read, ignore the end-of-file. Otherwise it is a protocol violation, so close the session immediately. While there, make relayd compile with DEBUG defined. Based on a diff from claudio@; tested by claudio@; OK claudio@ benno@ --- usr.sbin/relayd/relay.c | 6 +++--- usr.sbin/relayd/relay_http.c | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 1fef01f5c0f..1fd32dce1c5 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.192 2015/04/23 17:03:01 florian Exp $ */ +/* $OpenBSD: relay.c,v 1.193 2015/04/29 08:41:24 bluhm Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -988,7 +988,7 @@ relay_error(struct bufferevent *bev, short error, void *arg) dst = EVBUFFER_OUTPUT(cre->dst->bev); if (EVBUFFER_LENGTH(dst)) return; - } else + } else if (cre->toread == TOREAD_UNLIMITED || cre->toread == 0) return; relay_close(con, "done"); @@ -1263,7 +1263,7 @@ relay_from_table(struct rsession *con) return (-1); } host = rlt->rlt_host[idx]; - DPRINTF("%s: session %d: table %s host %s, p 0x%08x, idx %d", + DPRINTF("%s: session %d: table %s host %s, p 0x%016llx, idx %d", __func__, con->se_id, table->conf.name, host->conf.name, p, idx); while (host != NULL) { DPRINTF("%s: session %d: host %s", __func__, diff --git a/usr.sbin/relayd/relay_http.c b/usr.sbin/relayd/relay_http.c index 1d0b3220475..97bff864226 100644 --- a/usr.sbin/relayd/relay_http.c +++ b/usr.sbin/relayd/relay_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_http.c,v 1.43 2015/01/22 17:42:09 reyk Exp $ */ +/* $OpenBSD: relay_http.c,v 1.44 2015/04/29 08:41:24 bluhm Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter @@ -35,6 +35,9 @@ #include #include #include +#if DEBUG > 1 +#include +#endif #include "relayd.h" #include "http.h" -- 2.20.1