From b7d96314a0856b7df04d63d081cb73bc2b9471bf Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 5 May 2023 12:37:10 +0000 Subject: [PATCH] fix: ensure resource info is created properly the handle is not validated later, this change prevents nullptr dereference Signed-off-by: Mateusz Jablonski --- shared/source/gmm_helper/resource_info.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shared/source/gmm_helper/resource_info.cpp b/shared/source/gmm_helper/resource_info.cpp index d3492f1a98..76c52a9e48 100644 --- a/shared/source/gmm_helper/resource_info.cpp +++ b/shared/source/gmm_helper/resource_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,17 +7,25 @@ #include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/helpers/debug_helpers.h" + namespace NEO { GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESCREATE_PARAMS *resourceCreateParams) { - return new GmmResourceInfo(clientContext, resourceCreateParams); + auto resourceInfo = new GmmResourceInfo(clientContext, resourceCreateParams); + UNRECOVERABLE_IF(resourceInfo->peekHandle() == 0); + return resourceInfo; } GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) { - return new GmmResourceInfo(clientContext, inputGmmResourceInfo); + auto resourceInfo = new GmmResourceInfo(clientContext, inputGmmResourceInfo); + UNRECOVERABLE_IF(resourceInfo->peekHandle() == 0); + return resourceInfo; } GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) { - return new GmmResourceInfo(clientContext, inputGmmResourceInfo, openingHandle); + auto resourceInfo = new GmmResourceInfo(clientContext, inputGmmResourceInfo, openingHandle); + UNRECOVERABLE_IF(resourceInfo->peekHandle() == 0); + return resourceInfo; } } // namespace NEO