summaryrefslogtreecommitdiff
path: root/lib/tcp.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-05-15 15:39:20 +0200
committerLinus Nordberg <linus@nordberg.se>2013-05-15 15:39:20 +0200
commitf8207d6d51b665d6af54262c593372dd73eae0d0 (patch)
tree2cb6ac122f8566566ca9bfb4efd5b0e4c1eddbfb /lib/tcp.c
parentfba1c7d1a6418221a94965d0431bf7df0a9a74a0 (diff)
parent65b62d83ee72012d1171f1813b8f989f8805497c (diff)
Merge branch 'libradsec' into libradsec-server-support
Conflicts: lib/HACKING lib/Makefile.am lib/README lib/compat.h lib/conf.c lib/configure.ac lib/conn.c lib/conn.h lib/err.c lib/err.h lib/event.c lib/event.h lib/examples/Makefile.am lib/examples/client-blocking.c lib/examples/client.conf lib/include/radsec/radsec-impl.h lib/include/radsec/radsec.h lib/include/radsec/request-impl.h lib/include/radsec/request.h lib/packet.c lib/packet.h lib/peer.c lib/peer.h lib/request.c lib/send.c lib/tcp.c lib/tests/Makefile.am lib/tls.c lib/udp.c lib/util.c
Diffstat (limited to 'lib/tcp.c')
-rw-r--r--lib/tcp.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/tcp.c b/lib/tcp.c
index 7264244..8c7263f 100644
--- a/lib/tcp.c
+++ b/lib/tcp.c
@@ -1,5 +1,5 @@
-/* Copyright 2011,2013 NORDUnet A/S. All rights reserved.
- See LICENSE for licensing information. */
+/* Copyright 2011-2013 NORDUnet A/S. All rights reserved.
+ See LICENSE for licensing information. */
#if defined HAVE_CONFIG_H
#include <config.h>
@@ -37,9 +37,14 @@ _read_header (struct rs_message *msg)
msg->flags |= RS_MESSAGE_HEADER_READ;
msg->rpkt->length = (msg->hdr[2] << 8) + msg->hdr[3];
if (msg->rpkt->length < 20 || msg->rpkt->length > RS_MAX_PACKET_LEN)
- return rs_err_conn_push (msg->conn, RSE_INVALID_MSG,
- "invalid message length: %d",
- msg->rpkt->length);
+ {
+ rs_debug (("%s: invalid packet length: %d\n", __func__,
+ msg->rpkt->length));
+ rs_conn_disconnect (msg->conn);
+ return rs_err_conn_push (msg->conn, RSE_INVALID_MSG,
+ "invalid message length: %d",
+ msg->rpkt->length);
+ }
memcpy (msg->rpkt->data, msg->hdr, RS_HEADER_LEN);
bufferevent_setwatermark (TO_BASE_CONN(msg->conn)->bev, EV_READ,
msg->rpkt->length - RS_HEADER_LEN, 0);
@@ -49,8 +54,13 @@ _read_header (struct rs_message *msg)
else if (n < 0)
rs_debug (("%s: buffer frozen while reading header\n", __func__));
else /* Error: libevent gave us less than the low watermark. */
- return rs_err_conn_push_fl (msg->conn, RSE_INTERNAL, __FILE__, __LINE__,
- "got %d octets reading header", n);
+ {
+ rs_debug (("%s: got: %d octets reading header\n", __func__, n));
+ rs_conn_disconnect (msg->conn);
+ return rs_err_conn_push (msg->conn, RSE_INTERNAL,
+ "got %d octets reading header", n);
+ }
+
return RSE_OK;
}
@@ -90,8 +100,11 @@ _read_message (struct rs_message *msg)
- attribute sizes adding up correctly */
err = nr_packet_ok (msg->rpkt);
if (err)
- return rs_err_conn_push_fl (msg->conn, err, __FILE__, __LINE__,
- "invalid message");
+ {
+ rs_debug (("%s: %d: invalid packet\n", __func__, -err));
+ rs_conn_disconnect (msg->conn);
+ return rs_err_conn_push (msg->conn, -err, "invalid message");
+ }
#if defined (DEBUG)
/* Find out what happens if there's data left in the buffer. */
@@ -147,8 +160,7 @@ tcp_read_cb (struct bufferevent *bev, void *user_data)
if ((msg->flags & RS_MESSAGE_HEADER_READ) == 0)
if (_read_header (msg))
return; /* Invalid header. */
- if (_read_message (msg))
- return; /* Invalid message. */
+ _read_message (msg);
}
void