lapd: Warn if someone attempts to send an empty message
DATA REQ with a msgb_l3len(msg) == 0 message does not make any
sense, log an error and return immediately before attempting to
send an empty I frame in lapd_send_i.
diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c
index 74ffef3..fb79a2f 100644
--- a/src/gsm/lapd_core.c
+++ b/src/gsm/lapd_core.c
@@ -1731,6 +1731,13 @@
struct lapd_datalink *dl = lctx->dl;
struct msgb *msg = dp->oph.msg;
+ if (msgb_l3len(msg) == 0) {
+ LOGP(DLLAPD, LOGL_ERROR,
+ "writing an empty message is not possible.\n");
+ msgb_free(msg);
+ return -1;
+ }
+
LOGP(DLLAPD, LOGL_INFO,
"writing message to send-queue: l3len: %d\n", msgb_l3len(msg));
diff --git a/tests/lapd/lapd_test.c b/tests/lapd/lapd_test.c
index 8c6b0df..c924dbf 100644
--- a/tests/lapd/lapd_test.c
+++ b/tests/lapd/lapd_test.c
@@ -99,6 +99,16 @@
return msg;
}
+static struct msgb *create_empty_msg(void)
+{
+ struct msgb *msg;
+
+ msg = msgb_from_array(NULL, 0);
+ ASSERT(msgb_l3len(msg) == 0);
+ rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, 0, 0, 1);
+ return msg;
+}
+
static struct msgb *create_dummy_data_req(void)
{
struct msgb *msg;
@@ -284,6 +294,11 @@
rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp);
ASSERT(rc < 0);
+ /* check sending an empty L3 message fails */
+ rc = lapdm_rslms_recvmsg(create_empty_msg(), &bts_to_ms_channel);
+ ASSERT(rc == -1);
+ ASSERT(test_state.ms_read == 2);
+
/* clean up */
lapdm_channel_exit(&bts_to_ms_channel);
lapdm_channel_exit(&ms_to_bts_channel);