F-13458 - Stop the extend hashing loop on a short or failed read

pull/598/head
Aidan Garske 2026-09-08 11:27:28 -07:00
parent 18691a8b20
commit e7a00928bd
1 changed files with 9 additions and 1 deletions

View File

@ -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)