From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DB0F62237A4CA for ; Sun, 4 Feb 2018 21:44:17 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Feb 2018 21:49:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,463,1511856000"; d="scan'208";a="15867527" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.19]) by orsmga006.jf.intel.com with ESMTP; 04 Feb 2018 21:49:54 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Jaben Carsey , Jian J Wang Date: Mon, 5 Feb 2018 13:49:53 +0800 Message-Id: <20180205054953.212680-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 Subject: [PATCH] ShellPkg/map: Fix out-of-bound read when "map fsn" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Feb 2018 05:44:18 -0000 The below code reads additional one CHAR16 when copying content from Specific to NewSpecific. NewSpecific = AllocateCopyPool( StrSize(Specific) + sizeof(CHAR16), Specific ); The patch fixes this issue. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey Cc: Jian J Wang --- ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c index 3f5925f507..9166ca2205 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c @@ -1,7 +1,7 @@ /** @file Main file for map shell level 2 command. - Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
@@ -220,19 +220,25 @@ MappingListHasType( IN CONST BOOLEAN Consist ) { - CHAR16 *NewSpecific; - RETURN_STATUS Status; + CHAR16 *NewSpecific; + RETURN_STATUS Status; + UINTN Length; // // specific has priority // if (Specific != NULL) { - NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific); + Length = StrLen (Specific); + // + // Allocate enough buffer for Specific and potential ":" + // + NewSpecific = AllocatePool ((Length + 2) * sizeof(CHAR16)); if (NewSpecific == NULL){ return FALSE; } - if (NewSpecific[StrLen(NewSpecific)-1] != L':') { - Status = StrnCatS(NewSpecific, (StrSize(Specific) + sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":")); + StrCpyS (NewSpecific, Length + 2, Specific); + if (Specific[Length - 1] != L':') { + Status = StrnCatS(NewSpecific, Length + 2, L":", StrLen(L":")); if (EFI_ERROR (Status)) { FreePool(NewSpecific); return FALSE; -- 2.16.1.windows.1