Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tss2_PolicyGetDescription() does not null-terminate #2826

Closed
joholl opened this issue May 4, 2024 · 0 comments · Fixed by #2847
Closed

Tss2_PolicyGetDescription() does not null-terminate #2826

joholl opened this issue May 4, 2024 · 0 comments · Fixed by #2847
Assignees
Labels

Comments

@joholl
Copy link
Collaborator

joholl commented May 4, 2024

Tss2_PolicyGetDescription() returns a description field as a string (it uses strlen() internally), but it does not null-terminate the string for the caller. Instead of memcpy(), strcpy() should be used (and len/*size will have to be incremented by one).

I found this issue using clang-tidy. This is going to be fixed in an upcoming PR by me.

/** Retrieve the description field of a policy.
*
* The policy description is only a valid pointer for the lifetime of policy_ctx.
*
* @param[in] policy_ctx The policy context from Tss2_PolicyInstantiate.
* @param[in] description The description from the policy file.
*
* @retval TSS2_RC_SUCCESS After the end of the wait.
* @retval TSS2_FAPI_RC_BAD_REFERENCE a invalid null pointer is passed.
*/
TSS2_RC
Tss2_PolicyGetDescription(
TSS2_POLICY_CTX *policy_ctx,
char *buffer,
size_t *size)
{
policy_check_not_null(policy_ctx);
policy_check_not_null(size);
LOG_TRACE("called for policy_path(%s)",
policy_ctx->path);
const char *description = policy_ctx->policy.description;
size_t len = strlen(description);
/* NULL buffer let calller know size */
if (!buffer) {
*size = len;
return TSS2_RC_SUCCESS;
}
/* specified buffer but too small, let caller know size and error */
if (*size < len) {
*size = len;
return_if_error(TSS2_POLICY_RC_BUFFER_TOO_SMALL, "Specified buffer is too small");
}
/* all is well, copy it to user and let them know size */
*size = len;
memcpy(buffer, description, len);
LOG_TRACE("finished, returning: 0x0");
return TSS2_RC_SUCCESS;
}

I took the liberty to flag this as a bug. Feel free to remove the label if you think otherwise.

@joholl joholl added the bug label May 4, 2024
joholl pushed a commit that referenced this issue May 4, 2024
Fixes: #2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
joholl pushed a commit that referenced this issue May 7, 2024
Fixes: #2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
joholl pushed a commit to joholl/tpm2-tss that referenced this issue May 25, 2024
Fixes: tpm2-software#2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
joholl pushed a commit to joholl/tpm2-tss that referenced this issue Jun 4, 2024
Fixes: tpm2-software#2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
joholl pushed a commit to joholl/tpm2-tss that referenced this issue Jun 10, 2024
Fixes: tpm2-software#2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
joholl pushed a commit to joholl/tpm2-tss that referenced this issue Jul 5, 2024
Fixes: tpm2-software#2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants