From patchwork Thu Apr 2 08:32:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 6145201 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 462659F350 for ; Thu, 2 Apr 2015 08:28:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68D9F20328 for ; Thu, 2 Apr 2015 08:28:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8A6642034C for ; Thu, 2 Apr 2015 08:28:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F05616E99D; Thu, 2 Apr 2015 01:28:44 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 9182D6E99E for ; Thu, 2 Apr 2015 01:28:42 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 02 Apr 2015 01:28:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,509,1422950400"; d="scan'208";a="689364178" Received: from intel-desktop.iind.intel.com ([10.223.82.37]) by fmsmga001.fm.intel.com with ESMTP; 02 Apr 2015 01:28:42 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Thu, 2 Apr 2015 14:02:26 +0530 Message-Id: <1427963547-23614-12-git-send-email-praveen.paneri@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427963547-23614-1-git-send-email-praveen.paneri@intel.com> References: <1427963547-23614-1-git-send-email-praveen.paneri@intel.com> Cc: Praveen Paneri Subject: [Intel-gfx] [PATCH 11/12] xf86drm: Validate function return value X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Return value of drmHashCreate() and drmGetEntry() functions can be NULL. It should be validated before being used. Signed-off-by: Praveen Paneri --- xf86drm.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 373113b..d3a002a 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -178,20 +178,25 @@ static unsigned long drmGetKeyFromFd(int fd) drmHashEntry *drmGetEntry(int fd) { unsigned long key = drmGetKeyFromFd(fd); - void *value; + void *value = NULL; drmHashEntry *entry; if (!drmHashTable) drmHashTable = drmHashCreate(); - if (drmHashLookup(drmHashTable, key, &value)) { + if (drmHashTable && drmHashLookup(drmHashTable, key, &value)) { entry = drmMalloc(sizeof(*entry)); if (!entry) return NULL; entry->fd = fd; entry->f = NULL; entry->tagTable = drmHashCreate(); - drmHashInsert(drmHashTable, key, entry); + if (entry->tagTable) { + drmHashInsert(drmHashTable, key, entry); + } else { + drmFree(entry); + entry = NULL; + } } else { entry = value; } @@ -1219,6 +1224,8 @@ int drmClose(int fd) { unsigned long key = drmGetKeyFromFd(fd); drmHashEntry *entry = drmGetEntry(fd); + if(!entry) + return -ENOMEM; drmHashDestroy(entry->tagTable); entry->fd = 0; @@ -2258,6 +2265,8 @@ int drmGetInterruptFromBusID(int fd, int busnum, int devnum, int funcnum) int drmAddContextTag(int fd, drm_context_t context, void *tag) { drmHashEntry *entry = drmGetEntry(fd); + if (!entry) + return -ENOMEM; if (drmHashInsert(entry->tagTable, context, tag)) { drmHashDelete(entry->tagTable, context); @@ -2270,13 +2279,18 @@ int drmDelContextTag(int fd, drm_context_t context) { drmHashEntry *entry = drmGetEntry(fd); - return drmHashDelete(entry->tagTable, context); + if (entry) + return drmHashDelete(entry->tagTable, context); + return -ENOMEM; } void *drmGetContextTag(int fd, drm_context_t context) { - drmHashEntry *entry = drmGetEntry(fd); void *value; + drmHashEntry *entry = drmGetEntry(fd); + + if (!entry) + return NULL; if (drmHashLookup(entry->tagTable, context, &value)) return NULL;