From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=songpeng.li@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 0CFF32194D3AE for ; Thu, 27 Sep 2018 20:05:44 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2018 20:05:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,313,1534834800"; d="scan'208";a="74522519" Received: from songpeng.ccr.corp.intel.com ([10.239.158.28]) by fmsmga008.fm.intel.com with ESMTP; 27 Sep 2018 20:02:49 -0700 From: Songpeng Li To: edk2-devel@lists.01.org Cc: Fu Siyuan , Wu Jiaxin Date: Fri, 28 Sep 2018 11:02:34 +0800 Message-Id: <20180928030235.1080-2-songpeng.li@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20180928030235.1080-1-songpeng.li@intel.com> References: <20180928030235.1080-1-songpeng.li@intel.com> Subject: [PATCH v2 1/2] NetworkPkg/HttpDxe: fix read memory access overflow in HTTPBoot. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Sep 2018 03:05:44 -0000 The input param String of AsciiStrStr() requires a pointer to Null-terminated string, however in HttpTcpReceiveHeader(), the Buffersize before AllocateZeroPool() is equal to the size of TCP header, after the CopyMem(), it might not end with Null-terminator. It might cause memory access overflow. Cc: Fu Siyuan Cc: Wu Jiaxin Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Songpeng Li --- NetworkPkg/HttpDxe/HttpProto.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 94f89f5665..7d69429be7 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1914,10 +1914,10 @@ HttpTcpReceiveHeader ( } // - // Append the response string. + // Append the response string along with a Null-terminator. // *BufferSize = *SizeofHeaders + Fragment.Len; - Buffer = AllocateZeroPool (*BufferSize); + Buffer = AllocatePool (*BufferSize + 1); if (Buffer == NULL) { Status = EFI_OUT_OF_RESOURCES; return Status; @@ -1933,6 +1933,7 @@ HttpTcpReceiveHeader ( Fragment.Bulk, Fragment.Len ); + *(Buffer + *BufferSize) = '\0'; *HttpHeaders = Buffer; *SizeofHeaders = *BufferSize; @@ -2013,10 +2014,10 @@ HttpTcpReceiveHeader ( } // - // Append the response string. + // Append the response string along with a Null-terminator. // *BufferSize = *SizeofHeaders + Fragment.Len; - Buffer = AllocateZeroPool (*BufferSize); + Buffer = AllocatePool (*BufferSize + 1); if (Buffer == NULL) { Status = EFI_OUT_OF_RESOURCES; return Status; @@ -2032,6 +2033,7 @@ HttpTcpReceiveHeader ( Fragment.Bulk, Fragment.Len ); + *(Buffer + *BufferSize) = '\0'; *HttpHeaders = Buffer; *SizeofHeaders = *BufferSize; -- 2.18.0.windows.1