From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: zhichao.gao@intel.com) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by groups.io with SMTP; Wed, 07 Aug 2019 17:54:16 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2019 17:54:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,358,1559545200"; d="scan'208";a="193034400" Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga001.fm.intel.com with ESMTP; 07 Aug 2019 17:54:15 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Jaben Carsey , Ray Ni Subject: [PATCH] ShellPkg/UefiShellLevel2CommansLib: Pointer Resonse should be checked Date: Thu, 8 Aug 2019 08:54:05 +0800 Message-Id: <20190808005405.27080-1-zhichao.gao@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2049 ShellPkg\Library\UefiShellLevel2CommandsLib\Cp.c line 104 and ShellPkg\Library\UefiShellLevel2CommandsLib\Mv.c line 640, the pointer variable Response may be a NULL pointer. So we should make sure that it isn't NULL before dereference it. If Response is NULL that indicates a EFI_OUT_OF_RESOURCES error, directly return SHELL_ABORTED. Cc: Jaben Carsey Cc: Ray Ni Signed-off-by: Zhichao Gao --- .../Library/UefiShellLevel2CommandsLib/Cp.c | 42 ++++++++------- .../Library/UefiShellLevel2CommandsLib/Mv.c | 52 ++++++++++--------- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 18b05b5803..632d50229a 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -2,7 +2,7 @@ Main file for cp shell level 2 function. (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -101,24 +101,28 @@ CopySingleFile( // possibly return based on response // if (!SilentMode) { - switch (*(SHELL_PROMPT_RESPONSE*)Response) { - case ShellPromptResponseNo: - // - // return success here so we dont stop the process - // - return (SHELL_SUCCESS); - case ShellPromptResponseCancel: - *Resp = Response; - // - // indicate to stop everything - // - return (SHELL_ABORTED); - case ShellPromptResponseAll: - *Resp = Response; - case ShellPromptResponseYes: - break; - default: - return SHELL_ABORTED; + if (Response != NULL) { + switch (*(SHELL_PROMPT_RESPONSE*)Response) { + case ShellPromptResponseNo: + // + // return success here so we dont stop the process + // + return (SHELL_SUCCESS); + case ShellPromptResponseCancel: + *Resp = Response; + // + // indicate to stop everything + // + return (SHELL_ABORTED); + case ShellPromptResponseAll: + *Resp = Response; + case ShellPromptResponseYes: + break; + default: + return SHELL_ABORTED; + } + } else { + return SHELL_ABORTED; } } } diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c index 8c2852d7eb..2cfa588a8c 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c @@ -2,7 +2,7 @@ Main file for mv shell level 2 function. (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -637,29 +637,33 @@ ValidateAndMoveFiles( if (Response == NULL) { ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response); } - switch (*(SHELL_PROMPT_RESPONSE*)Response) { - case ShellPromptResponseNo: - FreePool(Response); - Response = NULL; - continue; - case ShellPromptResponseCancel: - *Resp = Response; - // - // indicate to stop everything - // - SHELL_FREE_NON_NULL(FullCwd); - return (SHELL_ABORTED); - case ShellPromptResponseAll: - *Resp = Response; - break; - case ShellPromptResponseYes: - FreePool(Response); - Response = NULL; - break; - default: - FreePool(Response); - SHELL_FREE_NON_NULL(FullCwd); - return SHELL_ABORTED; + if (Response != NULL) { + switch (*(SHELL_PROMPT_RESPONSE*)Response) { + case ShellPromptResponseNo: + FreePool(Response); + Response = NULL; + continue; + case ShellPromptResponseCancel: + *Resp = Response; + // + // indicate to stop everything + // + SHELL_FREE_NON_NULL(FullCwd); + return (SHELL_ABORTED); + case ShellPromptResponseAll: + *Resp = Response; + break; + case ShellPromptResponseYes: + FreePool(Response); + Response = NULL; + break; + default: + FreePool(Response); + SHELL_FREE_NON_NULL(FullCwd); + return SHELL_ABORTED; + } + } else { + return SHELL_ABORTED; } Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath); } -- 2.21.0.windows.1