From e7a00928bd3b15610fc3d1d0e4e4c26acdb2bc13 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Tue, 8 Sep 2026 11:27:28 -0700 Subject: [PATCH] F-13458 - Stop the extend hashing loop on a short or failed read --- examples/pcr/extend.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/pcr/extend.c b/examples/pcr/extend.c index 6926b0d1..f9a5138b 100644 --- a/examples/pcr/extend.c +++ b/examples/pcr/extend.c @@ -162,11 +162,19 @@ int TPM2_PCR_Extend_Test(void* userCtx, int argc, char *argv[]) rc = wc_HashInit(&dig, hashType); if (rc == 0) hashInitialized = 1; - while (rc == 0 && !XFEOF(fp)) { + while (rc == 0) { len = XFREAD(dataBuffer, 1, sizeof(dataBuffer), fp); if (len > 0) { rc = wc_HashUpdate(&dig, hashType, dataBuffer, (int)len); } + if (len < sizeof(dataBuffer)) { + /* Short read: end of file, or an input error to report */ + if (!XFEOF(fp)) { + printf("Error reading file %s\n", filename); + rc = BAD_FUNC_ARG; + } + break; + } } XFCLOSE(fp); if (rc == 0)