From 3d7fc71e989f530b1a5c61615713e4ba54fce9cc Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Wed, 10 May 2023 20:03:19 -0500 Subject: mutual-tls: fix clang-tidy warning ``` ../http/mutual_tls.hpp:77:35: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage] unsigned char usageChar = usage->data[i]; ``` Signed-off-by: Patrick Williams Change-Id: Icc6905f31fdd54b683fe7807eb72e9b78437b2d1 --- http/mutual_tls.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/http/mutual_tls.hpp b/http/mutual_tls.hpp index aee85c265e..f8af0f6f57 100644 --- a/http/mutual_tls.hpp +++ b/http/mutual_tls.hpp @@ -10,6 +10,7 @@ #include #include +#include inline std::shared_ptr verifyMtlsUser(const boost::asio::ip::address& clientIp, @@ -65,16 +66,15 @@ inline std::shared_ptr ASN1_BIT_STRING* usage = static_cast( X509_get_ext_d2i(peerCert, NID_key_usage, nullptr, nullptr)); - if (usage == nullptr) + if ((usage == nullptr) || (usage->data == nullptr)) { BMCWEB_LOG_DEBUG << "TLS usage is null"; return nullptr; } - for (int i = 0; i < usage->length; i++) + for (auto usageChar : + std::span(usage->data, static_cast(usage->length))) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - unsigned char usageChar = usage->data[i]; if (KU_DIGITAL_SIGNATURE & usageChar) { isKeyUsageDigitalSignature = true; -- cgit v1.2.3