public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: devel@edk2.groups.io, shenglei.zhang@intel.com
Cc: Siyuan Fu <siyuan.fu@intel.com>, Jiaxin Wu <jiaxin.wu@intel.com>,
	Laszlo Ersek <lersek@redhat.com>
Subject: Re: [edk2-devel] [PATCH v2] NetworkPkg/IScsiDxe: Fix the index of array TargetUrlp[]
Date: Mon, 14 Oct 2019 11:34:55 +0200	[thread overview]
Message-ID: <eb3e6246-2451-e43f-5b0d-56d66e6d0072@redhat.com> (raw)
In-Reply-To: <20191014031432.15984-1-shenglei.zhang@intel.com>

Hi Zhang,

On 10/14/19 5:14 AM, Zhang, Shenglei wrote:
> After the expression,
> 'CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);',
> the '\0' should be set to TargetUrl[Field->Len] rather than
> TargetUrl[Field->Len + 1].

^ This is one change, ...

> Besides the boundary check should be more strict.
> Field->Len should range from 0-254 rather than 0-255.

^ ... and here we have another change.

Can you split this in 2 patches?

> Cc: Siyuan Fu <siyuan.fu@intel.com>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> 
> v2: Add missing ')' which causes build failure.
> 
>   NetworkPkg/IScsiDxe/IScsiDhcp.c  | 7 ++++---
>   NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++---
>   2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c
> index d8c9fff6c65d..eac5b39991b7 100644
> --- a/NetworkPkg/IScsiDxe/IScsiDhcp.c
> +++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c
> @@ -122,11 +122,12 @@ IScsiDhcpExtractRootPath (
>     //
>     if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {
>       ConfigNvData->DnsMode = TRUE;
> -    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
> -      return EFI_INVALID_PARAMETER;
> +    if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) {
> +      Status = EFI_INVALID_PARAMETER;
> +      goto ON_EXIT;

This is a change in the code flow. So now we free he allocated TmpStr.
This is correct, but you did not commented that change in the 
description. So we currently have a memory leak. Please do not hide that 
kind of information in patches.

>       }
>       CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
> -    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
> +    ConfigNvData->TargetUrl[Field->Len] = '\0';

And here we have 1 byte of memory info leak.

Are you fixing a Security BZ?

>     } else {
>       ConfigNvData->DnsMode = FALSE;
>       ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
> diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
> index 86a872adeccc..be66e6684a0e 100644
> --- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c
> +++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
> @@ -161,11 +161,12 @@ IScsiDhcp6ExtractRootPath (
>     // Server name is expressed as domain name, just save it.
>     //
>     if (ConfigNvData->DnsMode) {
> -    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
> -      return EFI_INVALID_PARAMETER;
> +    if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) {
> +      Status = EFI_INVALID_PARAMETER;
> +      goto ON_EXIT;
>       }
>       CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
> -    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
> +    ConfigNvData->TargetUrl[Field->Len] = '\0';
>     } else {
>       ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
>       Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);
> 

  reply	other threads:[~2019-10-14  9:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14  3:14 [PATCH v2] NetworkPkg/IScsiDxe: Fix the index of array TargetUrlp[] Zhang, Shenglei
2019-10-14  9:34 ` Philippe Mathieu-Daudé [this message]
2019-10-14 14:02   ` [edk2-devel] " Zhang, Shenglei

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=eb3e6246-2451-e43f-5b0d-56d66e6d0072@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