F-3926 - Clamp -ownerauth length in seal_nv example

pull/503/head
Aidan Garske 2026-05-11 20:17:56 -07:00
parent 069dd33772
commit 4e16a160f4
1 changed files with 8 additions and 1 deletions

View File

@ -196,7 +196,14 @@ int TPM2_NVRAM_SealNV_Example(void* userCtx, int argc, char *argv[])
/* Set owner auth */
parent.hndl = TPM_RH_OWNER;
if (XSTRLEN(ownerAuth) > 0) {
parent.auth.size = (int)XSTRLEN(ownerAuth);
size_t authLen = XSTRLEN(ownerAuth);
if (authLen > sizeof(parent.auth.buffer)) {
fprintf(stderr, "-ownerauth value too long (max %zu)\n",
sizeof(parent.auth.buffer));
rc = BUFFER_E;
goto exit;
}
parent.auth.size = (UINT16)authLen;
XMEMCPY(parent.auth.buffer, ownerAuth, parent.auth.size);
}