diff options
author | Harald Welte <laforge@osmocom.org> | 2024-03-12 16:40:58 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2024-03-12 17:36:02 +0000 |
commit | c17dc5f55926ef88acb096f6af4356ff4b9dfb3f (patch) | |
tree | 24d192f15175478cf65ce601ea06b2d2441754f2 | |
parent | d047924463bfbcaf5f07b4617375a8a1946b01f0 (diff) |
osmo_stream_cli_send(): Drop data if client is not connected [yet]
The behaviour is undefined on what should happen if a stream client user
is trying to write data before the client socket is connected. In
osmo_io mode we would actually crash due to a NULL-pointer dereference.
Let's discard any sent data in this situation and print a related error log message.
This problem actually shows up with osmo-bsc Change-Id
Icce412e6ee69366c7b131c9bc1d51e8d44204917 where we convert CBSP over to
osmo_io - here in situations where a CBSP client (using stream_cli) was
previously connected but has lost its connection.
Change-Id: I18d2e8e850c23a32f5983a715fa8a18747b296cd
-rw-r--r-- | src/stream_cli.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/stream_cli.c b/src/stream_cli.c index 8312faf..2f5339c 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -1003,12 +1003,20 @@ void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg) OSMO_ASSERT(cli); OSMO_ASSERT(msg); + if (!osmo_stream_cli_is_connected(cli)) { + LOGSCLI(cli, LOGL_ERROR, "send: not connected, dropping data!\n"); + msgb_free(msg); + return; + } + switch (cli->mode) { case OSMO_STREAM_MODE_OSMO_FD: msgb_enqueue(&cli->tx_queue, msg); osmo_fd_write_enable(&cli->ofd); break; case OSMO_STREAM_MODE_OSMO_IO: + /* whenever osmo_stream_cli_is_connected() [see above check], we should have an iofd */ + OSMO_ASSERT(cli->iofd); if (cli->proto == IPPROTO_SCTP) rc = stream_iofd_sctp_send_msgb(cli->iofd, msg, MSG_NOSIGNAL); else |