diff mbox

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

Message ID 1428582142-5416-2-git-send-email-jerlbeck@sysmocom.de
State Accepted
Headers show

Commit Message

Jacob Erlbeck April 9, 2015, 12:22 p.m. UTC
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 mbox

Patch

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;
 }