From patchwork Mon Jun 12 22:02:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 9782863 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B143760382 for ; Mon, 12 Jun 2017 22:48:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5A8B286DB for ; Mon, 12 Jun 2017 22:48:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A573286D6; Mon, 12 Jun 2017 22:48:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BD7C27968 for ; Mon, 12 Jun 2017 22:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752856AbdFLWsN (ORCPT ); Mon, 12 Jun 2017 18:48:13 -0400 Received: from gateway30.websitewelcome.com ([192.185.160.12]:18598 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752666AbdFLWsM (ORCPT ); Mon, 12 Jun 2017 18:48:12 -0400 X-Greylist: delayed 1501 seconds by postgrey-1.27 at vger.kernel.org; Mon, 12 Jun 2017 18:48:12 EDT Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway30.websitewelcome.com (Postfix) with ESMTP id E36F520B2C for ; Mon, 12 Jun 2017 17:02:29 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id KXPadXSz6hVbKKXPadlmh6; Mon, 12 Jun 2017 17:02:15 -0500 Received: from [187.172.65.114] (port=48598 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.87) (envelope-from ) id 1dKXPp-003IA1-IV; Mon, 12 Jun 2017 17:02:29 -0500 Date: Mon, 12 Jun 2017 17:02:23 -0500 From: "Gustavo A. R. Silva" To: Samuel Ortiz , "David S. Miller" Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] nfc: nci: fix potential NULL pointer dereference Message-ID: <20170612220223.GA6326@embeddedgus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.172.65.114 X-Exim-ID: 1dKXPp-003IA1-IV X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [187.172.65.114]:48598 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 3 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP NULL check at line 76: if (conn_info) {, implies that pointer conn_info might be NULL, but this pointer is being previously dereferenced, which might cause a NULL pointer dereference. Add NULL check before dereferencing pointer conn_info in order to avoid a potential NULL pointer dereference. Addresses-Coverity-ID: 1362349 Signed-off-by: Gustavo A. R. Silva --- net/nfc/nci/core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index 61fff42..d2198ce 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -70,14 +70,13 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type, struct nci_conn_info *conn_info; list_for_each_entry(conn_info, &ndev->conn_info_list, list) { - if (conn_info->dest_type == dest_type) { + if (conn_info && conn_info->dest_type == dest_type) { if (!params) return conn_info->conn_id; - if (conn_info) { - if (params->id == conn_info->dest_params->id && - params->protocol == conn_info->dest_params->protocol) - return conn_info->conn_id; - } + + if (params->id == conn_info->dest_params->id && + params->protocol == conn_info->dest_params->protocol) + return conn_info->conn_id; } }