From patchwork Thu Apr 9 12:22:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Erlbeck X-Patchwork-Id: 459721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id DE0A7140079 for ; Thu, 9 Apr 2015 22:23:08 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id CBB8444F2; Thu, 9 Apr 2015 12:23:04 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org X-Greylist: delayed 160339 seconds by postgrey-1.34 at lists.osmocom.org; Thu, 09 Apr 2015 12:23:03 UTC Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 9436B44E5 for ; Thu, 9 Apr 2015 12:23:03 +0000 (UTC) Received: from sysmocom-tmp.am93.sysmocom.de (ip5b41c286.dynamic.kabel-deutschland.de [91.65.194.134]) by mail.sysmocom.de (Postfix) with ESMTPSA id D0681BD546; Thu, 9 Apr 2015 12:22:32 +0000 (UTC) From: Jacob Erlbeck To: openbsc@lists.osmocom.org Subject: [PATCH 2/2] gprs: Add assertion for msg != NULL to bssgp_msgb_alloc (Coverity) Date: Thu, 9 Apr 2015 14:22:22 +0200 Message-Id: <1428582142-5416-2-git-send-email-jerlbeck@sysmocom.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428582142-5416-1-git-send-email-jerlbeck@sysmocom.de> References: <1428582142-5416-1-git-send-email-jerlbeck@sysmocom.de> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" 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; }