public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ryan Harkin <ryan.harkin@linaro.org>
To: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	 "edk2-devel@lists.01.org" <edk2-devel@ml01.01.org>,
	Leif Lindholm <leif.lindholm@linaro.org>
Subject: Re: [PATCH v2 4/6] ArmPkg/SemihostFs: eliminate calls to deprecated string functions
Date: Wed, 26 Oct 2016 13:24:29 +0100	[thread overview]
Message-ID: <CAD0U-hLcNCETN4PEjo4YQJJDpNsuWkZy-PYp2yrNZr0n-E+Rkw@mail.gmail.com> (raw)
In-Reply-To: <e881eacb-03b5-10ad-cbec-82a566c6bc17@redhat.com>

On 26 October 2016 at 12:55, Laszlo Ersek <lersek@redhat.com> wrote:
> On 10/26/16 10:17, 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/Filesystem/SemihostFs/Arm/SemihostFs.c | 20 ++++++++++++--------
>>  1 file changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/ArmPkg/Filesystem/SemihostFs/Arm/SemihostFs.c b/ArmPkg/Filesystem/SemihostFs/Arm/SemihostFs.c
>> index 6efdad9ebcce..cf94ecd5d56f 100644
>> --- a/ArmPkg/Filesystem/SemihostFs/Arm/SemihostFs.c
>> +++ b/ArmPkg/Filesystem/SemihostFs/Arm/SemihostFs.c
>> @@ -207,11 +207,12 @@ FileOpen (
>>      return EFI_WRITE_PROTECTED;
>>    }
>>
>> -  AsciiFileName = AllocatePool (StrLen (FileName) + 1);
>> +  Length = StrLen (FileName) + 1;
>> +  AsciiFileName = AllocatePool (Length);
>>    if (AsciiFileName == NULL) {
>>      return EFI_OUT_OF_RESOURCES;
>>    }
>> -  UnicodeStrToAsciiStr (FileName, AsciiFileName);
>> +  UnicodeStrToAsciiStrS (FileName, AsciiFileName, Length);
>>
>>    // Opening '/', '\', '.', or the NULL pathname is trying to open the root directory
>>    if ((AsciiStrCmp (AsciiFileName, "\\") == 0) ||
>> @@ -463,7 +464,7 @@ FileDelete (
>>      NameSize = AsciiStrLen (Fcb->FileName);
>>      FileName = AllocatePool (NameSize + 1);
>>
>> -    AsciiStrCpy (FileName, Fcb->FileName);
>> +    AsciiStrCpyS (FileName, NameSize + 1, Fcb->FileName);
>>
>>      // Close the file if it's open.  Disregard return status,
>>      // since it might give an error if the file isn't open.
>> @@ -828,8 +829,10 @@ GetFilesystemInfo (
>>    EFI_FILE_SYSTEM_INFO  *Info;
>>    EFI_STATUS            Status;
>>    UINTN                 ResultSize;
>> +  UINTN                 StringSize;
>>
>> -  ResultSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (mSemihostFsLabel);
>> +  StringSize = StrSize (mSemihostFsLabel);
>> +  ResultSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StringSize;
>>
>>    if (*BufferSize >= ResultSize) {
>>      ZeroMem (Buffer, ResultSize);
>> @@ -843,7 +846,7 @@ GetFilesystemInfo (
>>      Info->FreeSpace  = 0;
>>      Info->BlockSize  = 0;
>>
>> -    StrCpy (Info->VolumeLabel, mSemihostFsLabel);
>> +    CopyMem (Info->VolumeLabel, mSemihostFsLabel, StringSize);
>>    } else {
>>      Status = EFI_BUFFER_TOO_SMALL;
>>    }
>> @@ -903,7 +906,7 @@ FileGetInfo (
>>      ResultSize = StrSize (mSemihostFsLabel);
>>
>>      if (*BufferSize >= ResultSize) {
>> -      StrCpy (Buffer, mSemihostFsLabel);
>> +      CopyMem (Buffer, mSemihostFsLabel, *BufferSize);
>
> This is still wrong; here *BufferSize is the size of the recipient
> buffer, passed in from the caller. As written, the code can overrun the
> *source* buffer. Please use
>
>       CopyMem (Buffer, mSemihostFsLabel, ResultSize);
>
> instead.
>
> With that update:
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>

I'll apply this update locally before I test the v2 series.


> Thanks
> Laszlo
>
>>        Status = EFI_SUCCESS;
>>      } else {
>>        Status = EFI_BUFFER_TOO_SMALL;
>> @@ -963,11 +966,12 @@ SetFileInfo (
>>      return EFI_ACCESS_DENIED;
>>    }
>>
>> -  AsciiFileName = AllocatePool (StrLen (Info->FileName) + 1);
>> +  Length = StrLen (Info->FileName) + 1;
>> +  AsciiFileName = AllocatePool (Length);
>>    if (AsciiFileName == NULL) {
>>      return EFI_OUT_OF_RESOURCES;
>>    }
>> -  UnicodeStrToAsciiStr (Info->FileName, AsciiFileName);
>> +  UnicodeStrToAsciiStrS (Info->FileName, AsciiFileName, Length);
>>
>>    FileSizeIsDifferent = (Info->FileSize != Fcb->Info.FileSize);
>>    FileNameIsDifferent = (AsciiStrCmp (AsciiFileName, Fcb->FileName) != 0);
>>
>


  reply	other threads:[~2016-10-26 12:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26  8:17 [PATCH v2 0/6] ArmPkg: eliminate calls to deprecated functions Ard Biesheuvel
2016-10-26  8:17 ` [PATCH v2 1/6] ArmPkg: add missing components Ard Biesheuvel
2016-10-26  8:17 ` [PATCH v2 2/6] ArmPkg/ArmCortexA9Lib RVCT: remove incompatible GCC include Ard Biesheuvel
2016-10-26  8:17 ` [PATCH v2 3/6] ArmPkg/LinuxLoader: eliminate calls to deprecated string functions Ard Biesheuvel
2016-10-26  8:17 ` [PATCH v2 4/6] ArmPkg/SemihostFs: " Ard Biesheuvel
2016-10-26 11:55   ` Laszlo Ersek
2016-10-26 12:24     ` Ryan Harkin [this message]
2016-10-26  8:17 ` [PATCH v2 5/6] ArmPkg/BdsLib: " Ard Biesheuvel
2016-10-26 12:04   ` Laszlo Ersek
2016-10-26  8:17 ` [PATCH v2 6/6] ArmPkg: enable -DDISABLE_NEW_DEPRECATED_INTERFACES Ard Biesheuvel
2016-10-26 12:11 ` [PATCH v2 0/6] ArmPkg: eliminate calls to deprecated functions Ryan Harkin
2016-10-26 12:13   ` Ard Biesheuvel
2016-10-26 12:21     ` Ryan Harkin
2016-10-26 13:06       ` 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=CAD0U-hLcNCETN4PEjo4YQJJDpNsuWkZy-PYp2yrNZr0n-E+Rkw@mail.gmail.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