public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: edk2-devel@lists.01.org, lersek@redhat.com, ryan.harkin@linaro.org
Subject: Re: [PATCH v2 7/9] EmbeddedPkg/EfiFileLib: eliminate deprecated string function calls
Date: Fri, 28 Oct 2016 15:37:16 +0100	[thread overview]
Message-ID: <20161028143716.GQ1161@bivouac.eciton.net> (raw)
In-Reply-To: <1477651478-16830-8-git-send-email-ard.biesheuvel@linaro.org>

On Fri, Oct 28, 2016 at 11:44:36AM +0100, Ard Biesheuvel wrote:
> Get rid of calls to unsafe string functions. These are deprecated and may
> be removed in the future.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c | 42 +++++++++++---------
>  1 file changed, 23 insertions(+), 19 deletions(-)
> 
> diff --git a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
> index 4d58c830861c..d3b65aa5a3e0 100644
> --- a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
> +++ b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
> @@ -384,9 +384,9 @@ EblFileDevicePath (
>  
>  
>    if ( *FileName != 0 ) {
> -    AsciiStrToUnicodeStr (FileName, UnicodeFileName);
> +    AsciiStrToUnicodeStrS (FileName, UnicodeFileName, MAX_PATHNAME);

So, I could suggest ARRAY_SIZE again, but since the define here makes
more semantic sense to begin with, it matters even less.

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

>    } else {
> -    AsciiStrToUnicodeStr ("\\", UnicodeFileName);
> +    AsciiStrToUnicodeStrS ("\\", UnicodeFileName, MAX_PATHNAME);
>    }
>  
>    Size = StrSize (UnicodeFileName);
> @@ -589,7 +589,7 @@ EblFvFileDevicePath (
>            &AuthenticationStatus
>            );
>          if (!EFI_ERROR (Status)) {
> -          UnicodeStrToAsciiStr (Section, AsciiSection);
> +          UnicodeStrToAsciiStrS (Section, AsciiSection, MAX_PATHNAME);
>            if (AsciiStriCmp (FileName, AsciiSection) == 0) {
>              FreePool (Section);
>              break;
> @@ -674,6 +674,7 @@ EfiOpen (
>    CHAR8                     *CwdPlusPathName;
>    UINTN                     Index;
>    EFI_SECTION_TYPE          ModifiedSectionType;
> +  UINTN                     AsciiLength;
>  
>    EblUpdateDeviceLists ();
>  
> @@ -706,7 +707,8 @@ EfiOpen (
>        }
>  
>        // We could add a current working directory concept
> -      CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName));
> +      AsciiLength = AsciiStrSize (gCwd) + AsciiStrSize (PathName);
> +      CwdPlusPathName = AllocatePool (AsciiLength);
>        if (CwdPlusPathName == NULL) {
>          return NULL;
>        }
> @@ -723,14 +725,14 @@ EfiOpen (
>            }
>          }
>        } else {
> -        AsciiStrCpy (CwdPlusPathName, gCwd);
> +        AsciiStrCpyS (CwdPlusPathName, AsciiLength, gCwd);
>          StrLen = AsciiStrLen (gCwd);
>          if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) {
> -          AsciiStrCat (CwdPlusPathName, "\\");
> +          AsciiStrCatS (CwdPlusPathName, AsciiLength, "\\");
>          }
>        }
>  
> -      AsciiStrCat (CwdPlusPathName, PathName);
> +      AsciiStrCatS (CwdPlusPathName, AsciiLength, PathName);
>        if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {
>          // Extra error check to make sure we don't recurse and blow stack
>          return NULL;
> @@ -745,7 +747,7 @@ EfiOpen (
>    }
>  
>    File->DeviceName = AllocatePool (StrLen);
> -  AsciiStrCpy (File->DeviceName, PathName);
> +  AsciiStrCpyS (File->DeviceName, StrLen, PathName);
>    File->DeviceName[FileStart - 1] = '\0';
>    File->FileName = &File->DeviceName[FileStart];
>    if (File->FileName[0] == '\0') {
> @@ -1611,7 +1613,7 @@ ExpandPath (
>  {
>    CHAR8   *NewPath;
>    CHAR8   *Work, *Start, *End;
> -  UINTN   StrLen;
> +  UINTN   StrLen, AllocLen;
>    INTN    i;
>  
>    if (Cwd == NULL || Path == NULL) {
> @@ -1625,11 +1627,12 @@ ExpandPath (
>    }
>  
>    StrLen = AsciiStrSize (Path);
> -  NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1);
> +  AllocLen = AsciiStrSize (Cwd) + StrLen + 1;
> +  NewPath = AllocatePool (AllocLen);
>    if (NewPath == NULL) {
>      return NULL;
>    }
> -  AsciiStrCpy (NewPath, Cwd);
> +  AsciiStrCpyS (NewPath, AllocLen, Cwd);
>  
>    End = Path + StrLen;
>    for (Start = Path ;;) {
> @@ -1640,7 +1643,7 @@ ExpandPath (
>      }
>  
>      // append path prior to ..
> -    AsciiStrnCat (NewPath, Start, Work - Start);
> +    AsciiStrnCatS (NewPath, AllocLen, Start, Work - Start);
>      StrLen = AsciiStrLen (NewPath);
>      for (i = StrLen; i >= 0; i--) {
>        if (NewPath[i] == ':') {
> @@ -1663,7 +1666,7 @@ ExpandPath (
>    }
>  
>    // Handle the path that remains after the ..
> -  AsciiStrnCat (NewPath, Start, End - Start);
> +  AsciiStrnCatS (NewPath, AllocLen, Start, End - Start);
>  
>    return NewPath;
>  }
> @@ -1686,7 +1689,7 @@ EfiSetCwd (
>    )
>  {
>    EFI_OPEN_FILE *File;
> -  UINTN         Len;
> +  UINTN         Len, AllocLen;
>    CHAR8         *Path;
>  
>    if (Cwd == NULL) {
> @@ -1729,17 +1732,18 @@ EfiSetCwd (
>  
>    // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be
>    // relative to the current gCwd or not.
> -  gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10);
> +  AllocLen = AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10;
> +  gCwd = AllocatePool (AllocLen);
>    if (gCwd == NULL) {
>      return EFI_INVALID_PARAMETER;
>    }
>  
> -  AsciiStrCpy (gCwd, File->DeviceName);
> +  AsciiStrCpyS (gCwd, AllocLen, File->DeviceName);
>    if (File->FileName == NULL) {
> -    AsciiStrCat (gCwd, ":\\");
> +    AsciiStrCatS (gCwd, AllocLen, ":\\");
>    } else {
> -    AsciiStrCat (gCwd, ":");
> -    AsciiStrCat (gCwd, File->FileName);
> +    AsciiStrCatS (gCwd, AllocLen, ":");
> +    AsciiStrCatS (gCwd, AllocLen, File->FileName);
>    }
>  
>  
> -- 
> 2.7.4
> 


  reply	other threads:[~2016-10-28 14:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-28 10:44 [PATCH v2 0/9] EmbeddedPkg: eliminate calls to deprecated functions Ard Biesheuvel
2016-10-28 10:44 ` [PATCH v2 1/9] EmbeddedPkg/AndroidFastbootTransportTcpDxe: remove broken hostname handling Ard Biesheuvel
2016-10-28 12:40   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 2/9] EmbeddedPkg: remove unused PrePiHobListPointerLib Ard Biesheuvel
2016-10-28 12:40   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 3/9] EmbeddedPkg: add missing modules Ard Biesheuvel
2016-10-28 12:41   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 4/9] EmbeddedPkg/GdbDebugAgent: fix VOID* cast of incorrect size Ard Biesheuvel
2016-10-28 12:47   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 5/9] EmbeddedPkg/AndroidFastboot: eliminate deprecated string function calls Ard Biesheuvel
2016-10-28 13:18   ` Laszlo Ersek
2016-10-28 13:36   ` Leif Lindholm
2016-10-28 13:40     ` Ard Biesheuvel
2016-10-28 13:52       ` Leif Lindholm
2016-10-28 14:04         ` Ard Biesheuvel
2016-10-28 14:05         ` Laszlo Ersek
2016-10-28 13:41     ` Laszlo Ersek
2016-10-28 10:44 ` [PATCH v2 6/9] EmbeddedPkg/Ebl: " Ard Biesheuvel
2016-10-28 13:31   ` Laszlo Ersek
2016-10-28 14:31   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 7/9] EmbeddedPkg/EfiFileLib: " Ard Biesheuvel
2016-10-28 14:37   ` Leif Lindholm [this message]
2016-10-28 10:44 ` [PATCH v2 8/9] EmbeddedPkg/MmcDxe: " Ard Biesheuvel
2016-10-28 13:40   ` Laszlo Ersek
2016-10-28 14:39   ` Leif Lindholm
2016-10-28 10:44 ` [PATCH v2 9/9] EmbeddedPkg: enable -DDISABLE_NEW_DEPRECATED_INTERFACES Ard Biesheuvel
2016-10-28 14:40   ` Leif Lindholm
2016-10-28 15:16 ` [PATCH v2 0/9] EmbeddedPkg: eliminate calls to deprecated functions Ard Biesheuvel

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=20161028143716.GQ1161@bivouac.eciton.net \
    --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