Repository navigation
tpm2: Fix return value on full buffer in ASN1PushLength - #660
Conversation
In ASN1PushLength(), the return condition was '(ctx->offset > 0) ? start - ctx->offset : 0'. When pushed length octets exactly fill the remaining buffer space, ctx->offset reaches 0 (the valid start of the buffer, whereas negative offset indicates buffer overflow). The function erroneously returned 0 (indicating failure) instead of the number of marshaled bytes. Check 'ctx->offset >= 0' to correctly handle a full buffer, matching the error check convention in the rest of TpmASN1.c. Co-authored-by: IBM Bob <noreply@ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
In ASN1PushLength(), the return condition was '(ctx->offset > 0) ? start - ctx->offset : 0'. When pushed length octets exactly fill the remaining buffer space, ctx->offset reaches 0 (the valid start of the buffer, whereas negative offset indicates buffer overflow). The function erroneously returned 0 (indicating failure) instead of the number of marshaled bytes.
Check 'ctx->offset >= 0' to correctly handle a full buffer, matching the error check convention in the rest of TpmASN1.c.
Summary by CodeRabbit