From patchwork Mon Apr 25 11:00:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neels Hofmeyr X-Patchwork-Id: 614384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 3qtjxf3nycz9t5X for ; Mon, 25 Apr 2016 21:03:02 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id ACC5E13E45; Mon, 25 Apr 2016 11:03:00 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [IPv6:2001:bf0:c000::1:8]) by lists.osmocom.org (Postfix) with ESMTP id D6E6D13E36 for ; Mon, 25 Apr 2016 11:02:58 +0000 (UTC) X-Envelope-From: nhofmeyr@sysmocom.de X-Envelope-To: Received: from localhost (p4FC1F563.dip0.t-ipconnect.de [79.193.245.99]) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id u3PB2vDh007032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Apr 2016 13:02:58 +0200 From: Neels Hofmeyr To: openbsc@lists.osmocom.org Subject: [PATCH] queue_new(): fix NULL dereference on allocation failure Date: Mon, 25 Apr 2016 13:00:10 +0200 Message-Id: <1461582010-3322-1-git-send-email-nhofmeyr@sysmocom.de> X-Mailer: git-send-email 2.1.4 X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Coverity complains about a 'Dereference before null check' on *queue. So, push the NULL check further up. Though I doubt that 'return EOF' is the proper way to handle allocation failure, this patch is only about the NULL dereference. Fixes: CID#57918 --- gtp/queue.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gtp/queue.c b/gtp/queue.c index 7c971b0..5b4d849 100644 --- a/gtp/queue.c +++ b/gtp/queue.c @@ -127,16 +127,15 @@ int queue_new(struct queue_t **queue) if (QUEUE_DEBUG) printf("queue_new\n"); *queue = calloc(1, sizeof(struct queue_t)); + if (!(*queue)) + return EOF; (*queue)->next = 0; (*queue)->first = -1; (*queue)->last = -1; if (QUEUE_DEBUG) queue_print(*queue); - if (*queue) - return 0; - else - return EOF; + return 0; } /*! \brief Deallocates queue structure */