aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2017-04-20 18:40:37 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2017-04-20 18:48:47 +0200
commit05dd583d906733d2bfe66329809d41c3dee54723 (patch)
tree92afd5969d12b7ded3ffd8693a26d22cf05a9c4c
parent256a0a6960ae4020560f1662a4c15f03e7c70cf7 (diff)
libmsc: make pitfall in gsm0408_dispatch() more obvious
The function gsm0408_dispatch() accepts a message buffer pointer and accesses the l3h pointer. Even in a properly allocated message buffer, this may lead into a segfault if the user forgets to set the l3h pointer. This commit adds assertions to popup a more expressive error message.
-rw-r--r--openbsc/src/libmsc/gsm_04_08.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 6ec78ae1e..9ca3c09cc 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -3583,13 +3583,17 @@ void cm_service_request_concludes(struct gsm_subscriber_connection *conn,
/* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */
int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
- struct gsm48_hdr *gh = msgb_l3(msg);
- uint8_t pdisc = gsm48_hdr_pdisc(gh);
+ struct gsm48_hdr *gh;
+ uint8_t pdisc;
int rc = 0;
+ OSMO_ASSERT(msg->l3h)
OSMO_ASSERT(conn);
OSMO_ASSERT(msg);
+ gh = msgb_l3(msg);
+ pdisc = gsm48_hdr_pdisc(gh);
+
LOGP(DRLL, LOGL_DEBUG, "Dispatching 04.08 message %s (0x%x:0x%x)\n",
gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)),
pdisc, gsm48_hdr_msg_type(gh));