From nobody Mon May 6 16:58:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517809802073890.1188105324123; Sun, 4 Feb 2018 21:50:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 20BA3223AF830; Sun, 4 Feb 2018 21:44:19 -0800 (PST) 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) 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 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 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,463,1511856000"; d="scan'208";a="15867527" From: Ruiyu Ni To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The below code reads additional one CHAR16 when copying content from Specific to NewSpecific. NewSpecific =3D 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 Reviewed-by: Jaben Carsey --- ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c b/ShellPkg/L= ibrary/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. =20 - 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
=20 @@ -220,19 +220,25 @@ MappingListHasType( IN CONST BOOLEAN Consist ) { - CHAR16 *NewSpecific; - RETURN_STATUS Status; + CHAR16 *NewSpecific; + RETURN_STATUS Status; + UINTN Length; =20 // // specific has priority // if (Specific !=3D NULL) { - NewSpecific =3D AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), S= pecific); + Length =3D StrLen (Specific); + // + // Allocate enough buffer for Specific and potential ":" + // + NewSpecific =3D AllocatePool ((Length + 2) * sizeof(CHAR16)); if (NewSpecific =3D=3D NULL){ return FALSE; } - if (NewSpecific[StrLen(NewSpecific)-1] !=3D L':') { - Status =3D StrnCatS(NewSpecific, (StrSize(Specific) + sizeof(CHAR16)= )/sizeof(CHAR16), L":", StrLen(L":")); + StrCpyS (NewSpecific, Length + 2, Specific); + if (Specific[Length - 1] !=3D L':') { + Status =3D StrnCatS(NewSpecific, Length + 2, L":", StrLen(L":")); if (EFI_ERROR (Status)) { FreePool(NewSpecific); return FALSE; --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel