public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Liming Gao" <liming.gao@intel.com>
To: "Feng, YunhuaX" <yunhuax.feng@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Feng, Bob C" <bob.c.feng@intel.com>
Subject: Re: [PATCH] Tools/FitGen: Check the input file path before open it
Date: Wed, 19 Feb 2020 12:59:00 +0000	[thread overview]
Message-ID: <c7f82ae30f65450bab1a93eb1e9618bb@intel.com> (raw)
In-Reply-To: <f10d62e938054cdd95f7d76c5e89a510@intel.com>

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Feng, YunhuaX <yunhuax.feng@intel.com>
> Sent: Wednesday, February 19, 2020 8:13 PM
> To: devel@edk2.groups.io
> Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>
> Subject: [PATCH] Tools/FitGen: Check the input file path before open it
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2117
> 
> avoid path traversal attack check.
> 
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
> ---
>  Silicon/Intel/Tools/FitGen/FitGen.c | 47 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
> 
> diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
> index 8122c10ebb..42d10d85bc 100644
> --- a/Silicon/Intel/Tools/FitGen/FitGen.c
> +++ b/Silicon/Intel/Tools/FitGen/FitGen.c
> @@ -401,10 +401,38 @@ SetMem (
>      *(Pointer++) = Value;
>    }
>    return Buffer;
>  }
> 
> +BOOLEAN
> +CheckPath (
> +  IN CHAR8 * String
> +)
> +{
> +  //
> +  //Return FLASE if  input file path include % character or is NULL
> +  //
> +  CHAR8 *StrPtr;
> +
> +  StrPtr = String;
> +  if (StrPtr == NULL) {
> +    return FALSE;
> +  }
> +
> +  if (*StrPtr == 0) {
> +    return FALSE;
> +  }
> +
> +  while (*StrPtr != '\0') {
> +    if (*StrPtr == '%') {
> +      return FALSE;
> +    }
> +    StrPtr++;
> +  }
> +  return TRUE;
> +}
> +
>  STATUS
>  ReadInputFile (
>    IN CHAR8    *FileName,
>    OUT UINT8   **FileData,
>    OUT UINT32  *FileSize,
> @@ -433,10 +461,19 @@ Returns:
>  {
>    FILE                        *FpIn;
>    UINT32                      TempResult;
> 
>    //
> +  //Check the File Path
> +  //
> +  if (!CheckPath(FileName)) {
> +
> +    Error (NULL, 0, 0, "File path is invalid!", NULL);
> +    return STATUS_ERROR;
> +  }
> +
> +  //
>    // Open the Input FvRecovery.fv file
>    //
>    if ((FpIn = fopen (FileName, "rb")) == NULL) {
>      //
>      // Return WARNING, let caller make decision
> @@ -2759,10 +2796,19 @@ Returns:
>  --*/
>  {
>    FILE                        *FpOut;
> 
>    //
> +  //Check the File Path
> +  //
> +  if (!CheckPath(FileName)) {
> +
> +    Error (NULL, 0, 0, "File path is invalid!", NULL);
> +    return STATUS_ERROR;
> +  }
> +
> +  //
>    // Open the output FvRecovery.fv file
>    //
>    if ((FpOut = fopen (FileName, "w+b")) == NULL) {
>      Error (NULL, 0, 0, "Unable to open file", "%s", FileName);
>      return STATUS_ERROR;
> @@ -2980,10 +3026,11 @@ Returns:
>    UINT8                       *FdFileBuffer;
>    UINT32                      FdFileSize;
> 
>    UINT8                       *AcmBuffer;
> 
> +  FileBufferRaw = NULL;
>    //
>    // Step 0: Check FV or FD
>    //
>    if (((strcmp (argv[1], "-D") == 0) ||
>         (strcmp (argv[1], "-d") == 0)) ) {
> --
> 2.12.2.windows.2


      reply	other threads:[~2020-02-19 12:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 12:12 [PATCH] Tools/FitGen: Check the input file path before open it Feng, YunhuaX
2020-02-19 12:59 ` Liming Gao [this message]

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=c7f82ae30f65450bab1a93eb1e9618bb@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