From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"rebecca@nuviainc.com" <rebecca@nuviainc.com>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "Briskman, Yitzhak" <yitzhak.briskman@intel.com>,
"Wang, Jian J" <jian.j.wang@intel.com>,
"Zhu, Yonghong" <yonghong.zhu@intel.com>
Subject: Re: [edk2-devel] [edk2-libc Patch] StdLib/LibC/StdLib: Handle possible math overflow in malloc()
Date: Wed, 18 Aug 2021 22:18:51 +0000 [thread overview]
Message-ID: <CO1PR11MB4929A48534B7C5E73D226576D2FF9@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <98195237-5de2-ac43-2f33-a5fd01ae4d72@nuviainc.com>
I just followed the DEBUG() message style in the rest of the malloc() function.
It does guarantee that the message starts at the left column, which is important
if the same console is used for both stdout and DEBUG() which can happen for
UEFI Applications.
PEI/DXE/MM/SMM components may have a dedicated device for DEBUG() messages or
may run before the local console is initialized, so the extra \n is not needed.
Mike
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rebecca Cran
> Sent: Wednesday, August 18, 2021 3:08 PM
> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Briskman, Yitzhak <yitzhak.briskman@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Zhu, Yonghong
> <yonghong.zhu@intel.com>
> Subject: Re: [edk2-devel] [edk2-libc Patch] StdLib/LibC/StdLib: Handle possible math overflow in malloc()
>
> Reviewed-by: Rebecca Cran <rebecca@nuviainc.com>
>
>
> Not sure the first \n is needed though.
>
>
> --
>
> Rebecca Cran
>
>
> On 8/18/21 4:03 PM, Michael D Kinney wrote:
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1510
> >
> > Check for addition overflow in malloc() when computing NodeSize
> > and return error if overflow is detected.
> >
> > Cc: Rebecca Cran <rebecca@nuviainc.com>
> > Cc: Yitzhak Briskman <yitzhak.briskman@intel.com>
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> > Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
> > ---
> > StdLib/LibC/StdLib/Malloc.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/StdLib/LibC/StdLib/Malloc.c b/StdLib/LibC/StdLib/Malloc.c
> > index c131b9e..7bf8827 100644
> > --- a/StdLib/LibC/StdLib/Malloc.c
> > +++ b/StdLib/LibC/StdLib/Malloc.c
> > @@ -94,6 +94,12 @@ malloc(size_t Size)
> > return NULL;
> > }
> >
> > + if ((Size + sizeof(CPOOL_HEAD)) < Size) {
> > + RetVal = NULL;
> > + errno = ENOMEM;
> > + DEBUG((DEBUG_ERROR, "\nERROR malloc: Size overflow\n"));
> > + }
> > +
> > NodeSize = (UINTN)(Size + sizeof(CPOOL_HEAD));
> >
> > DEBUG((DEBUG_POOL, "malloc(%d): NodeSz: %d", Size, NodeSize));
>
>
>
>
prev parent reply other threads:[~2021-08-18 22:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 22:03 [edk2-libc Patch] StdLib/LibC/StdLib: Handle possible math overflow in malloc() Michael D Kinney
2021-08-18 22:08 ` [edk2-devel] " Rebecca Cran
2021-08-18 22:18 ` Michael D Kinney [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=CO1PR11MB4929A48534B7C5E73D226576D2FF9@CO1PR11MB4929.namprd11.prod.outlook.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