From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, shenglei.zhang@intel.com
Cc: Jiewen Yao <jiewen.yao@intel.com>,
Jian J Wang <jian.j.wang@intel.com>,
Chao Zhang <chao.b.zhang@intel.com>
Subject: Re: [edk2-devel] [PATCH] SecurityPkg/Tpm2Help.c: Add boundary check for array
Date: Fri, 6 Dec 2019 10:27:12 +0100 [thread overview]
Message-ID: <b25fc5f2-793e-599d-c581-461e9b86f07a@redhat.com> (raw)
In-Reply-To: <20191206014933.36648-1-shenglei.zhang@intel.com>
On 12/06/19 02:49, Zhang, Shenglei wrote:
> Add 'Index < HASH_COUNT' to ensure things out of boundary
> of digests[] can not be visited.
>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Chao Zhang <chao.b.zhang@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> index 36c240d1221c..a7d4e3ab5373 100644
> --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> @@ -299,7 +299,7 @@ GetDigestListSize (
> UINT32 TotalSize;
>
> TotalSize = sizeof(DigestList->count);
> - for (Index = 0; Index < DigestList->count; Index++) {
> + for (Index = 0; Index < DigestList->count, Index < HASH_COUNT; Index++) {
> DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg);
> TotalSize += sizeof(DigestList->digests[Index].hashAlg) + DigestSize;
> }
>
Nacked-by: Laszlo Ersek <lersek@redhat.com>
The comma operator is either functionally wrong in this context, or
stylistically wrong. From the C standard:
The left operand of a comma operator is evaluated as a void
expression; there is a sequence point after its evaluation. Then the
right operand is evaluated; the result has its type and value. [...]
In case we *only* need to check (Index < HASH_COUNT), then the patch is
stylistically incorrect: the (Index < DigestList->count) condition
should simply be removed.
In case we need to check *both* conditions, then the patch is
functionally wrong: we should either use the logical AND (&&) operator,
instead of the comma:
Index < DigestList->count && Index < HASH_COUNT
or invoke the MIN() function-like macro:
Index < MIN ((UINTN)DigestList->count, (UINTN)HASH_COUNT)
Thanks
Laszlo
next prev parent reply other threads:[~2019-12-06 9:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-06 1:49 [PATCH] SecurityPkg/Tpm2Help.c: Add boundary check for array Zhang, Shenglei
2019-12-06 2:04 ` Yao, Jiewen
2019-12-16 6:57 ` Zhang, Shenglei
2019-12-06 9:27 ` Laszlo Ersek [this message]
2019-12-16 6:58 ` [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=b25fc5f2-793e-599d-c581-461e9b86f07a@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