public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jiaxin Wu <jiaxin.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>, Fu Siyuan <siyuan.fu@intel.com>,
	Wang Fan <fan.wang@intel.com>, Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch 3/5] MdeModulePkg/DxeHttpLib: Check the input parameters for some APIs.
Date: Tue, 26 Dec 2017 09:33:47 +0800	[thread overview]
Message-ID: <1514252029-12720-4-git-send-email-jiaxin.wu@intel.com> (raw)
In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com>

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Include/Library/HttpLib.h       |  1 +
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/Library/HttpLib.h
index 8539820..88b56ae 100644
--- a/MdeModulePkg/Include/Library/HttpLib.h
+++ b/MdeModulePkg/Include/Library/HttpLib.h
@@ -370,10 +370,11 @@ HttpFindHeader (
   @param[in]      FieldName           FieldName of this HttpHeader, a NULL terminated ASCII string.
   @param[in]      FieldValue          FieldValue of this HttpHeader, a NULL terminated ASCII string.
 
 
   @retval EFI_SUCCESS             The FieldName and FieldValue are set into HttpHeader successfully.
+  @retval EFI_INVALID_PARAMETER   The parameter is invalid.
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.
 
 **/
 EFI_STATUS
 EFIAPI
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 27b94e3..38ded5d 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1396,10 +1396,14 @@ HttpIsMessageComplete (
   IN VOID              *MsgParser
   )
 {
   HTTP_BODY_PARSER      *Parser;
 
+  if (MsgParser == NULL) {
+    return FALSE;
+  }
+
   Parser = (HTTP_BODY_PARSER*) MsgParser;
 
   if (Parser->State == BodyParserComplete) {
     return TRUE;
   }
@@ -1497,10 +1501,11 @@ AsciiStrGetNextToken (
   @param[in]  FieldName           FieldName of this HttpHeader, a NULL terminated ASCII string.
   @param[in]  FieldValue          FieldValue of this HttpHeader, a NULL terminated ASCII string.
 
 
   @retval EFI_SUCCESS             The FieldName and FieldValue are set into HttpHeader successfully.
+  @retval EFI_INVALID_PARAMETER   The parameter is invalid.
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.
 
 **/
 EFI_STATUS
 EFIAPI
@@ -1511,10 +1516,14 @@ HttpSetFieldNameAndValue (
   )
 {
   UINTN                       FieldNameSize;
   UINTN                       FieldValueSize;
 
+  if (HttpHeader == NULL || FieldName == NULL || FieldValue == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   if (HttpHeader->FieldName != NULL) {
     FreePool (HttpHeader->FieldName);
   }
   if (HttpHeader->FieldValue != NULL) {
     FreePool (HttpHeader->FieldValue);
@@ -1728,14 +1737,10 @@ HttpGenRequestMessage (
   VOID                             *HttpHdr;
   EFI_HTTP_HEADER                  **AppendList;
   UINTN                            Index;
   EFI_HTTP_UTILITIES_PROTOCOL      *HttpUtilitiesProtocol;
 
-
-  ASSERT (Message != NULL);
-
-  *RequestMsg           = NULL;
   Status                = EFI_SUCCESS;
   HttpHdrSize           = 0;
   MsgSize               = 0;
   Success               = FALSE;
   HttpHdr               = NULL;
@@ -1746,11 +1751,12 @@ HttpGenRequestMessage (
   // 1. If we have a Request, we cannot have a NULL Url
   // 2. If we have a Request, HeaderCount can not be non-zero
   // 3. If we do not have a Request, HeaderCount should be zero
   // 4. If we do not have Request and Headers, we need at least a message-body
   //
-  if ((Message->Data.Request != NULL && Url == NULL) ||
+  if ((Message == NULL || RequestMsg == NULL || RequestMsgSize == NULL) || 
+      (Message->Data.Request != NULL && Url == NULL) ||
       (Message->Data.Request != NULL && Message->HeaderCount == 0) ||
       (Message->Data.Request == NULL && Message->HeaderCount != 0) ||
       (Message->Data.Request == NULL && Message->HeaderCount == 0 && Message->BodyLength == 0)) {
     return EFI_INVALID_PARAMETER;
   }
@@ -1827,10 +1833,11 @@ HttpGenRequestMessage (
   MsgSize += Message->BodyLength;
 
   //
   // memory for the string that needs to be sent to TCP
   //
+  *RequestMsg           = NULL;
   *RequestMsg = AllocateZeroPool (MsgSize);
   if (*RequestMsg == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
     goto Exit;
   }
@@ -2052,11 +2059,19 @@ HttpIsValidHttpHeader (
   IN  CHAR8            *FieldName
   )
 {
   UINTN                       Index;
 
+  if (FieldName == NULL) {
+    return FALSE;
+  }
+
   for (Index = 0; Index < DeleteCount; Index++) {
+    if (DeleteList[Index] == NULL) {
+      continue;
+    }
+    
     if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {
       return FALSE;
     }
   }
 
-- 
1.9.5.msysgit.1



  parent reply	other threads:[~2017-12-26  1:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26  1:33 [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Jiaxin Wu
2017-12-26  1:33 ` [Patch 1/5] MdeModulePkg/DxeHttpLib: Add boundary condition check Jiaxin Wu
2017-12-26  1:56   ` Gary Lin
2017-12-26  2:21     ` Wu, Jiaxin
2017-12-26  1:33 ` [Patch 2/5] MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen Jiaxin Wu
2017-12-26  1:33 ` Jiaxin Wu [this message]
2017-12-26  1:33 ` [Patch 4/5] MdeModulePkg/DxeHttpLib: Correct some return Status Jiaxin Wu
2017-12-26  1:33 ` [Patch 5/5] MdeModulePkg/DxeHttpLib: Refine some coding style Jiaxin Wu
2017-12-26  1:40 ` [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Fu, Siyuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514252029-12720-4-git-send-email-jiaxin.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox