summaryrefslogtreecommitdiff
path: root/lib/tcp.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-05-15 11:57:09 +0200
committerLinus Nordberg <linus@nordberg.se>2013-05-15 11:57:09 +0200
commit65b62d83ee72012d1171f1813b8f989f8805497c (patch)
treed90452346d8a2c8cba610315f483ef50fed0b698 /lib/tcp.c
parentfed9094cd8cda69605d0c103acd14308379b6eb0 (diff)
Don't crash on reading invalid messages.
Also, invoke disconnected callback and close connection in error cases.
Diffstat (limited to 'lib/tcp.c')
-rw-r--r--lib/tcp.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/tcp.c b/lib/tcp.c
index 8ea6a5e..e2b1a2f 100644
--- a/lib/tcp.c
+++ b/lib/tcp.c
@@ -38,7 +38,9 @@ _read_header (struct rs_packet *pkt)
pkt->rpkt->length = (pkt->hdr[2] << 8) + pkt->hdr[3];
if (pkt->rpkt->length < 20 || pkt->rpkt->length > RS_MAX_PACKET_LEN)
{
- conn_close (&pkt->conn);
+ rs_debug (("%s: invalid packet length: %d\n",
+ __func__, pkt->rpkt->length));
+ rs_conn_disconnect (pkt->conn);
return rs_err_conn_push (pkt->conn, RSE_INVALID_PKT,
"invalid packet length: %d",
pkt->rpkt->length);
@@ -55,7 +57,8 @@ _read_header (struct rs_packet *pkt)
}
else /* Error: libevent gave us less than the low watermark. */
{
- conn_close (&pkt->conn);
+ rs_debug (("%s: got: %d octets reading header\n", __func__, n));
+ rs_conn_disconnect (pkg->conn);
return rs_err_conn_push_fl (pkt->conn, RSE_INTERNAL, __FILE__, __LINE__,
"got %d octets reading header", n);
}
@@ -100,8 +103,9 @@ _read_packet (struct rs_packet *pkt)
err = nr_packet_ok (pkt->rpkt);
if (err != RSE_OK)
{
- conn_close (&pkt->conn);
- return rs_err_conn_push_fl (pkt->conn, err, __FILE__, __LINE__,
+ rs_debug (("%s: %d: invalid packet\n", __func__, -err));
+ rs_conn_disconnect (pkt->conn);
+ return rs_err_conn_push_fl (pkt->conn, -err, __FILE__, __LINE__,
"invalid packet");
}