public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	edk2-devel@ml01.01.org, leif.lindholm@linaro.org
Subject: Re: [PATCH 3/6] ArmPkg/LinuxLoader: eliminate calls to deprecated string functions
Date: Tue, 25 Oct 2016 12:53:13 +0200	[thread overview]
Message-ID: <4819b517-89e8-3c61-ebb7-a718ae4be909@redhat.com> (raw)
In-Reply-To: <1477325206-24646-4-git-send-email-ard.biesheuvel@linaro.org>

On 10/24/16 18:06, Ard Biesheuvel wrote:
> Remove calls to deprecated string functions like AsciiStrCpy() and
> UnicodeStrToAsciiStr()
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmPkg/Application/LinuxLoader/Arm/LinuxAtag.c | 2 +-
>  ArmPkg/Application/LinuxLoader/LinuxLoader.c   | 6 ++++--
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/ArmPkg/Application/LinuxLoader/Arm/LinuxAtag.c b/ArmPkg/Application/LinuxLoader/Arm/LinuxAtag.c
> index fd7ee9c8624d..0b3e2489c758 100644
> --- a/ArmPkg/Application/LinuxLoader/Arm/LinuxAtag.c
> +++ b/ArmPkg/Application/LinuxLoader/Arm/LinuxAtag.c
> @@ -72,7 +72,7 @@ SetupCmdlineTag (
>      mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;
>  
>      /* place CommandLine into tag */
> -    AsciiStrCpy (mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);
> +    AsciiStrCpyS (mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, LineLength, CmdLine);
>  
>      // move pointer to next tag
>      mLinuxKernelCurrentAtag = next_tag_address (mLinuxKernelCurrentAtag);

Apparently nothing in this file checks if the tags being added still
actually fit in the preallocated space (which is EFI_SIZE_TO_PAGES
(ATAG_MAX_SIZE)). The change does preserve the previous behavior ("copy
the full string").

> diff --git a/ArmPkg/Application/LinuxLoader/LinuxLoader.c b/ArmPkg/Application/LinuxLoader/LinuxLoader.c
> index 70b960b66f0e..76697c3a8c9d 100644
> --- a/ArmPkg/Application/LinuxLoader/LinuxLoader.c
> +++ b/ArmPkg/Application/LinuxLoader/LinuxLoader.c
> @@ -61,6 +61,7 @@ LinuxLoaderEntryPoint (
>    LIST_ENTRY                          *ResourceLink;
>    SYSTEM_MEMORY_RESOURCE              *Resource;
>    EFI_PHYSICAL_ADDRESS                SystemMemoryBase;
> +  UINTN                               Length;
>  
>    Status = gBS->LocateProtocol (
>                    &gEfiDevicePathFromTextProtocolGuid,
> @@ -182,12 +183,13 @@ LinuxLoaderEntryPoint (
>    }
>  
>    if (LinuxCommandLine != NULL) {
> -    AsciiLinuxCommandLine = AllocatePool ((StrLen (LinuxCommandLine) + 1) * sizeof (CHAR8));
> +    Length = StrLen (LinuxCommandLine) + 1;
> +    AsciiLinuxCommandLine = AllocatePool (Length);
>      if (AsciiLinuxCommandLine == NULL) {
>        Status = EFI_OUT_OF_RESOURCES;
>        goto Error;
>      }
> -    UnicodeStrToAsciiStr (LinuxCommandLine, AsciiLinuxCommandLine);
> +    UnicodeStrToAsciiStrS (LinuxCommandLine, AsciiLinuxCommandLine, Length);
>    }
>  
>    //
> 

I prefer to call character counts without the terminating NUL "Length",
and character counts with the terminating NUL "Size", but that's just a
personal preference. (And the rest of this code uses Length differently
already, for example in "LineLength" itself, near the top.)

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


  reply	other threads:[~2016-10-25 10:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 16:06 [PATCH 0/6] ArmPkg: eliminate calls to deprecated functions Ard Biesheuvel
2016-10-24 16:06 ` [PATCH 1/6] ArmPkg: add missing components Ard Biesheuvel
2016-10-25 12:51   ` Leif Lindholm
2016-10-24 16:06 ` [PATCH 2/6] ArmPkg/ArmCortexA9Lib RVCT: remove incompatible GCC include Ard Biesheuvel
2016-10-25 12:53   ` Leif Lindholm
2016-10-24 16:06 ` [PATCH 3/6] ArmPkg/LinuxLoader: eliminate calls to deprecated string functions Ard Biesheuvel
2016-10-25 10:53   ` Laszlo Ersek [this message]
2016-10-25 10:56     ` Ard Biesheuvel
2016-10-25 11:08       ` Ryan Harkin
2016-10-25 11:09         ` Ard Biesheuvel
2016-10-24 16:06 ` [PATCH 4/6] ArmPkg/SemihostFs: " Ard Biesheuvel
2016-10-25 11:11   ` Laszlo Ersek
2016-10-24 16:06 ` [PATCH 5/6] ArmPkg/BdsLib: " Ard Biesheuvel
2016-10-25 11:16   ` Laszlo Ersek
2016-10-24 16:06 ` [PATCH 6/6] ArmPkg: enable -DDISABLE_NEW_DEPRECATED_INTERFACES Ard Biesheuvel
2016-10-25 11:17   ` Laszlo Ersek
2016-10-25 11:32 ` [PATCH 0/6] ArmPkg: eliminate calls to deprecated functions Ryan Harkin

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=4819b517-89e8-3c61-ebb7-a718ae4be909@redhat.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