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....@intel.com>
> Cc: Jian J Wang <jian.j.w...@intel.com>
> Cc: Chao Zhang <chao.b.zh...@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zh...@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 <ler...@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


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51824): https://edk2.groups.io/g/devel/message/51824
Mute This Topic: https://groups.io/mt/67403438/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to