diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-07 20:25:51 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-01-12 22:00:37 +0300 |
commit | 46ff87bade273c75f71f940c5770d30e7a29595b (patch) | |
tree | e9c093a73a4cffda570a14e84908e029010a2d2b | |
parent | ecd6a3a20ab128ae9d3e356d6250695800dc13be (diff) | |
download | bmcweb-46ff87bade273c75f71f940c5770d30e7a29595b.tar.xz |
Enable reinterpre_cast checks
We seem to use reinterpret cast in a few cases unfortunately. For the
moment, simply ignore most of them, and make it so we don't get more.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic860cf922576b18cdc8d51d6132f5a9cbcc1d9dc
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | http/http_connection.hpp | 6 | ||||
-rw-r--r-- | include/hostname_monitor.hpp | 1 | ||||
-rw-r--r-- | include/ibm/locks.hpp | 2 | ||||
-rw-r--r-- | include/pam_authenticate.hpp | 17 | ||||
-rw-r--r-- | include/ssl_key_handler.hpp | 23 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 17 |
7 files changed, 44 insertions, 23 deletions
diff --git a/.clang-tidy b/.clang-tidy index 8a14cfa695..61f2c68d82 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -202,6 +202,7 @@ clang-analyzer-valist.ValistBase, clang-analyzer-webkit.NoUncountedMemberChecker, clang-analyzer-webkit.RefCntblBaseVirtualDtor, cppcoreguidelines-init-variables, +cppcoreguidelines-pro-type-reinterpret-cast, cppcoreguidelines-special-member-functions, misc-misplaced-const, #misc-no-recursion, diff --git a/http/http_connection.hpp b/http/http_connection.hpp index 77886c5da1..840f2b6ceb 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -98,9 +98,11 @@ class Connection : { adaptor.set_verify_mode(boost::asio::ssl::verify_peer); std::string id = "bmcweb"; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + auto* idC = reinterpret_cast<const unsigned char*>(id.c_str()); int ret = SSL_set_session_id_context( - adaptor.native_handle(), - reinterpret_cast<const unsigned char*>(id.c_str()), + adaptor.native_handle(), idC, static_cast<unsigned int>(id.length())); if (ret == 0) { diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp index 65a5c1c34a..30186b650e 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -103,6 +103,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */, X509_get_ext_d2i(cert, NID_netscape_comment, nullptr, nullptr)); if (asn1) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) std::string_view comment(reinterpret_cast<const char*>(asn1->data), static_cast<size_t>(asn1->length)); BMCWEB_LOG_DEBUG << "x509Comment: " << comment; diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp index 8e04b8424b..4fbb50360d 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -530,7 +530,9 @@ inline bool Lock::isConflictRequest(const LockRequests& refLockRequestStructure) inline bool Lock::checkByte(uint64_t resourceId1, uint64_t resourceId2, uint32_t position) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) uint8_t* p = reinterpret_cast<uint8_t*>(&resourceId1); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) uint8_t* q = reinterpret_cast<uint8_t*>(&resourceId2); BMCWEB_LOG_DEBUG << "Comparing bytes " << std::to_string(p[position]) << "," diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp index a24270f4b6..0ce0bb4a84 100644 --- a/include/pam_authenticate.hpp +++ b/include/pam_authenticate.hpp @@ -32,6 +32,7 @@ inline int pamFunctionConversation(int numMsg, const struct pam_message** msg, /* Assume PAM is only prompting for the password as hidden input */ /* Allocate memory only when PAM_PROMPT_ECHO_OFF is encounterred */ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) char* appPass = reinterpret_cast<char*>(appdataPtr); size_t appPassSize = std::strlen(appPass); @@ -39,8 +40,14 @@ inline int pamFunctionConversation(int numMsg, const struct pam_message** msg, { return PAM_CONV_ERR; } - - char* pass = reinterpret_cast<char*>(malloc(appPassSize + 1)); + // IDeally we'd like to avoid using malloc here, but because we're + // passing off ownership of this to a C application, there aren't a lot + // of sane ways to avoid it. + + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc)' + void* passPtr = malloc(appPassSize + 1); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + char* pass = reinterpret_cast<char*>(passPtr); if (pass == nullptr) { return PAM_BUF_ERR; @@ -48,15 +55,17 @@ inline int pamFunctionConversation(int numMsg, const struct pam_message** msg, std::strncpy(pass, appPass, appPassSize + 1); - void* ptr = - calloc(static_cast<size_t>(numMsg), sizeof(struct pam_response)); + size_t numMsgSize = static_cast<size_t>(numMsg); + void* ptr = calloc(numMsgSize, sizeof(struct pam_response)); if (ptr == nullptr) { free(pass); return PAM_BUF_ERR; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) *resp = reinterpret_cast<pam_response*>(ptr); + resp[i]->resp = pass; return PAM_SUCCESS; diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp index eb59bee88a..dbe596a586 100644 --- a/include/ssl_key_handler.hpp +++ b/include/ssl_key_handler.hpp @@ -281,15 +281,20 @@ inline void generateSslCertificate(const std::string& filepath, // get the subject name X509_NAME* name = X509_get_subject_name(x509); - X509_NAME_add_entry_by_txt( - name, "C", MBSTRING_ASC, - reinterpret_cast<const unsigned char*>("US"), -1, -1, 0); - X509_NAME_add_entry_by_txt( - name, "O", MBSTRING_ASC, - reinterpret_cast<const unsigned char*>("OpenBMC"), -1, -1, 0); - X509_NAME_add_entry_by_txt( - name, "CN", MBSTRING_ASC, - reinterpret_cast<const unsigned char*>(cn.c_str()), -1, -1, 0); + using x509String = const unsigned char; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + x509String* country = reinterpret_cast<x509String*>("US"); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + x509String* company = reinterpret_cast<x509String*>("OpenBMC"); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + x509String* cnStr = reinterpret_cast<x509String*>(cn.c_str()); + + X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, country, -1, -1, + 0); + X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, company, -1, -1, + 0); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, cnStr, -1, -1, + 0); // set the CSR options X509_set_issuer_name(x509, name); diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index ddd124bb49..2cd35df428 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -136,8 +136,10 @@ inline static int getJournalMetadata(sd_journal* journal, size_t length = 0; int ret = 0; // Get the metadata from the requested field of the journal entry - ret = sd_journal_get_data(journal, field.data(), - reinterpret_cast<const void**>(&data), &length); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + const void** dataVoid = reinterpret_cast<const void**>(&data); + + ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); if (ret < 0) { return ret; @@ -3462,18 +3464,17 @@ inline void requestRoutesPostCodesEntryAdditionalData(App& app) return; } - auto& [tID, code] = postcodes[value]; - if (code.empty()) + auto& [tID, c] = postcodes[value]; + if (c.empty()) { BMCWEB_LOG_INFO << "No found post code data"; messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); return; } - - std::string_view strData( - reinterpret_cast<const char*>(code.data()), - code.size()); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + const char* d = reinterpret_cast<const char*>(c.data()); + std::string_view strData(d, c.size()); asyncResp->res.addHeader("Content-Type", "application/octet-stream"); |