[PATCH 2/2] gprs: Add assertion for msg != NULL to bssgp_msgb_alloc (Coverity)

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Thu Apr 9 12:22:22 UTC 2015


Currently out-of-memory is not handled by bssgp_msgb_alloc, leading
to SEGV failures if msgb_alloc_headroom returns NULL.

This commit adds an OSMO_ASSERT to catch this case, which improves
the situation only slightly. But bssgp_msgb_alloc is used in many
places without checking the return value, so just adding a
conditional early NULL return would not fix the issue either.

Fixes: Coverity CID 1293377
Sponsored-by: On-Waves ehf
---
 src/gb/gprs_bssgp_util.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/gb/gprs_bssgp_util.c b/src/gb/gprs_bssgp_util.c
index fe66f46..3c42e4d 100644
--- a/src/gb/gprs_bssgp_util.c
+++ b/src/gb/gprs_bssgp_util.c
@@ -71,6 +71,10 @@ const char *bssgp_cause_str(enum gprs_bssgp_cause cause)
 struct msgb *bssgp_msgb_alloc(void)
 {
 	struct msgb *msg = msgb_alloc_headroom(4096, 128, "BSSGP");
+
+	/* TODO: Add handling of msg == NULL to this function and to all callers */
+	OSMO_ASSERT(msg != NULL);
+
 	msgb_bssgph(msg) = msg->data;
 	return msg;
 }
-- 
1.9.1




More information about the OpenBSC mailing list