From 438685f083d819adc45e43f81a8af0a935acc760 Mon Sep 17 00:00:00 2001 From: Johannes Holland Date: Sat, 4 May 2024 15:21:55 +0200 Subject: [PATCH] clang-tidy: fix bugprone-not-null-terminated-result Fixes: #2826 Signed-off-by: Johannes Holland --- .clang-tidy | 3 --- src/tss2-policy/tss2_policy.c | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index dc90198a1..0d8e9250b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,8 +9,6 @@ # [TODO] # -bugprone-narrowing-conversions # [TODO] -# -bugprone-not-null-terminated-result -# [TODO] # # -clang-analyzer-optin.performance.Padding # We prefer logical/semantic order over (potentially insignificant) @@ -28,7 +26,6 @@ Checks: "\ -bugprone-easily-swappable-parameters, \ -bugprone-implicit-widening-of-multiplication-result, \ -bugprone-narrowing-conversions, \ - -bugprone-not-null-terminated-result, \ \ clang-analyzer, \ -clang-analyzer-optin.performance.Padding, \ diff --git a/src/tss2-policy/tss2_policy.c b/src/tss2-policy/tss2_policy.c index c20e29304..92c5631ef 100644 --- a/src/tss2-policy/tss2_policy.c +++ b/src/tss2-policy/tss2_policy.c @@ -404,7 +404,8 @@ Tss2_PolicyGetDescription( policy_ctx->path); const char *description = policy_ctx->policy.description; - size_t len = strlen(description); + /* length including null termination */ + size_t len = strlen(description) + 1; /* NULL buffer let calller know size */ if (!buffer) { @@ -418,9 +419,9 @@ Tss2_PolicyGetDescription( 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 */ + /* all is well, copy it to user (including null termination) and let them know size */ *size = len; - memcpy(buffer, description, len); + strcpy(buffer, description); LOG_TRACE("finished, returning: 0x0"); return TSS2_RC_SUCCESS;