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
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp
index 65a5c1c..30186b6 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -103,6 +103,7 @@
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 8e04b84..4fbb503 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -530,7 +530,9 @@
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 a24270f..0ce0bb4 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -32,6 +32,7 @@
/* 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 @@
{
return PAM_CONV_ERR;
}
+ // 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.
- char* pass = reinterpret_cast<char*>(malloc(appPassSize + 1));
+ // 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 @@
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 eb59bee..dbe596a 100644
--- a/include/ssl_key_handler.hpp
+++ b/include/ssl_key_handler.hpp
@@ -281,15 +281,20 @@
// 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);