From 46f799b224744979294e5f94f225bb1a720e5063 Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Thu, 11 Aug 2011 04:37:17 +0200 Subject: MNCC: Never send zero-length msgb packets to the socket This will cause the remote end to read 0 bytes, which is interpreted as if we cleanly closed the socket, making the remote end close their side of the socket, which would lead to us closing our side of the socket, so we should never send such a packet. --- openbsc/src/libmsc/mncc_sock.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'openbsc') diff --git a/openbsc/src/libmsc/mncc_sock.c b/openbsc/src/libmsc/mncc_sock.c index 5ef9922d2..d8caf0754 100644 --- a/openbsc/src/libmsc/mncc_sock.c +++ b/openbsc/src/libmsc/mncc_sock.c @@ -165,6 +165,13 @@ static int mncc_sock_write(struct osmo_fd *bfd) bfd->when &= ~BSC_FD_WRITE; + /* bug hunter 8-): maybe someone forgot msgb_put(...) ? */ + if (!msgb_length(msg)) { + LOGP(DMNCC, LOGL_ERROR, "message type (%d) with ZERO " + "bytes!\n", mncc_prim->msg_type); + goto dontsend; + } + /* try to send it over the socket */ rc = write(bfd->fd, msgb_data(msg), msgb_length(msg)); if (rc == 0) @@ -176,6 +183,8 @@ static int mncc_sock_write(struct osmo_fd *bfd) } goto close; } + +dontsend: /* _after_ we send it, we can deueue */ msg2 = msgb_dequeue(&net->upqueue); assert(msg == msg2); -- cgit v1.2.3