diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | crow/include/crow/http_connection.h | 11 | ||||
-rw-r--r-- | crow/include/crow/http_request.h | 2 | ||||
-rw-r--r-- | crow/include/crow/http_server.h | 8 | ||||
-rw-r--r-- | crow/include/crow/logging.h | 1 | ||||
-rw-r--r-- | crow/include/crow/query_string.h | 25 | ||||
-rw-r--r-- | crow/include/crow/routing.h | 127 | ||||
-rw-r--r-- | crow/include/crow/timer_queue.h | 9 | ||||
-rw-r--r-- | crow/include/crow/utility.h | 36 | ||||
-rw-r--r-- | include/dbus_monitor.hpp | 2 | ||||
-rw-r--r-- | include/dbus_utility.hpp | 7 | ||||
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 9 | ||||
-rw-r--r-- | include/pam_authenticate.hpp | 2 | ||||
-rw-r--r-- | include/persistent_data_middleware.hpp | 4 | ||||
-rw-r--r-- | include/sessions.hpp | 10 | ||||
-rw-r--r-- | include/ssl_key_handler.hpp | 97 | ||||
-rw-r--r-- | redfish-core/include/privileges.hpp | 10 | ||||
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 56 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 26 | ||||
-rw-r--r-- | redfish-core/lib/managers.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/power.hpp | 5 | ||||
-rw-r--r-- | redfish-core/lib/sensors.hpp | 16 | ||||
-rw-r--r-- | redfish-core/lib/thermal.hpp | 2 |
23 files changed, 224 insertions, 249 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1300c23573..3bedfe7836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) -set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h index c02f4ec1e3..d7598bd168 100644 --- a/crow/include/crow/http_connection.h +++ b/crow/include/crow/http_connection.h @@ -345,7 +345,7 @@ class Connection }; ctx = detail::Context<Middlewares...>(); - req->middlewareContext = (void*)&ctx; + req->middlewareContext = static_cast<void*>(&ctx); req->ioService = &adaptor.get_executor().context(); detail::middlewareCallHelper< 0, decltype(ctx), decltype(*middlewares), Middlewares...>( @@ -388,14 +388,13 @@ class Connection needToCallAfterHandlers = false; // call all afterHandler of middlewares - detail::afterHandlersCallHelper<((int)sizeof...(Middlewares) - 1), - decltype(ctx), - decltype(*middlewares)>( - *middlewares, ctx, *req, res); + detail::afterHandlersCallHelper< + static_cast<int>(sizeof...(Middlewares) - 1), decltype(ctx), + decltype(*middlewares)>(*middlewares, ctx, *req, res); } // auto self = this->shared_from_this(); - res.completeRequestHandler = res.completeRequestHandler = [] {}; + res.completeRequestHandler = [] {}; if (!adaptor.lowest_layer().is_open()) { diff --git a/crow/include/crow/http_request.h b/crow/include/crow/http_request.h index 0ba02664de..fa12c26e92 100644 --- a/crow/include/crow/http_request.h +++ b/crow/include/crow/http_request.h @@ -27,7 +27,7 @@ struct Request { } - const boost::beast::http::verb method() const + boost::beast::http::verb method() const { return req.method(); } diff --git a/crow/include/crow/http_server.h b/crow/include/crow/http_server.h index 75b49a463f..eace64fcfe 100644 --- a/crow/include/crow/http_server.h +++ b/crow/include/crow/http_server.h @@ -121,17 +121,17 @@ class Server boost::asio::deadline_timer timer(*ioService); timer.expires_from_now(boost::posix_time::seconds(1)); - std::function<void(const boost::system::error_code& ec)> handler; - handler = [&](const boost::system::error_code& ec) { + std::function<void(const boost::system::error_code& ec)> fHandler; + fHandler = [&](const boost::system::error_code& ec) { if (ec) { return; } timerQueue.process(); timer.expires_from_now(boost::posix_time::seconds(1)); - timer.async_wait(handler); + timer.async_wait(fHandler); }; - timer.async_wait(handler); + timer.async_wait(fHandler); if (tickFunction && tickInterval.count() > 0) { diff --git a/crow/include/crow/logging.h b/crow/include/crow/logging.h index 9da47b733a..0d24940820 100644 --- a/crow/include/crow/logging.h +++ b/crow/include/crow/logging.h @@ -30,6 +30,7 @@ class ILogHandler { public: virtual void log(std::string message, LogLevel level) = 0; + virtual ~ILogHandler(){}; }; class CerrLogHandler : public ILogHandler diff --git a/crow/include/crow/query_string.h b/crow/include/crow/query_string.h index 553960eb6f..b38d0ed1be 100644 --- a/crow/include/crow/query_string.h +++ b/crow/include/crow/query_string.h @@ -19,16 +19,16 @@ int qsStrncmp(const char* s, const char* qs, size_t n); * Also decodes the value portion of the k/v pair *in-place*. In a future * enhancement it will also have a compile-time option of sorting qs_kv * alphabetically by key. */ -int qsParse(char* qs, char* qs_kv[], int qs_kv_size); +size_t qsParse(char* qs, char* qs_kv[], size_t qs_kv_size); /* Used by qs_parse to decode the value portion of a k/v pair */ -int qsDecode(char* qs); +size_t qsDecode(char* qs); /* Looks up the value according to the key on a pre-processed query string * A future enhancement will be a compile-time option to look up the key * in a pre-sorted qs_kv array via a binary search. */ // char * qs_k2v(const char * key, char * qs_kv[], int qs_kv_size); -char* qsK2v(const char* key, char* const* qs_kv, int qs_kv_size, int nth); +char* qsK2v(const char* key, char* const* qs_kv, size_t qs_kv_size, size_t nth); /* Non-destructive lookup of value, based on key. User provides the * destinaton string and length. */ @@ -127,9 +127,9 @@ inline int qsStrncmp(const char* s, const char* qs, size_t n) } } -inline int qsParse(char* qs, char* qs_kv[], int qs_kv_size) +inline size_t qsParse(char* qs, char* qs_kv[], size_t qs_kv_size) { - int i, j; + size_t i, j; char* substrPtr; for (i = 0; i < qs_kv_size; i++) @@ -184,9 +184,9 @@ inline int qsParse(char* qs, char* qs_kv[], int qs_kv_size) return i; } -inline int qsDecode(char* qs) +inline size_t qsDecode(char* qs) { - int i = 0, j = 0; + size_t i = 0, j = 0; while (BMCWEB_QS_ISQSCHR(qs[j])) { @@ -217,10 +217,10 @@ inline int qsDecode(char* qs) return i; } -inline char* qsK2v(const char* key, char* const* qs_kv, int qs_kv_size, - int nth = 0) +inline char* qsK2v(const char* key, char* const* qs_kv, size_t qs_kv_size, + size_t nth = 0) { - int i; + size_t i; size_t keyLen, skip; keyLen = strlen(key); @@ -353,7 +353,8 @@ class QueryString keyValuePairs.resize(maxKeyValuePairsCount); - int count = qsParse(&url[0], &keyValuePairs[0], maxKeyValuePairsCount); + size_t count = + qsParse(&url[0], &keyValuePairs[0], maxKeyValuePairsCount); keyValuePairs.resize(count); } @@ -391,7 +392,7 @@ class QueryString std::string plus = name + "[]"; char* element = nullptr; - int count = 0; + size_t count = 0; while (1) { element = qsK2v(plus.c_str(), keyValuePairs.data(), diff --git a/crow/include/crow/routing.h b/crow/include/crow/routing.h index 746e115894..d7e3fd33f0 100644 --- a/crow/include/crow/routing.h +++ b/crow/include/crow/routing.h @@ -63,7 +63,8 @@ class BaseRule } protected: - uint32_t methodsBitfield{1 << (int)boost::beast::http::verb::get}; + uint32_t methodsBitfield{ + 1 << static_cast<int>(boost::beast::http::verb::get)}; std::string rule; std::string nameStr; @@ -362,29 +363,33 @@ template <typename T> struct RuleParameterTraits using self_t = T; WebSocketRule& websocket() { - auto p = new WebSocketRule(((self_t*)this)->rule); - ((self_t*)this)->ruleToUpgrade.reset(p); + self_t* s = static_cast<self_t*>(this); + auto p = new WebSocketRule(s->rule); + s->ruleToUpgrade.reset(p); return *p; } self_t& name(std::string name) noexcept { - ((self_t*)this)->nameStr = std::move(name); - return (self_t&)*this; + self_t* s = static_cast<self_t*>(this); + s->nameStr = std::move(name); + return *s; } self_t& methods(boost::beast::http::verb method) { - ((self_t*)this)->methodsBitfield = 1 << (int)method; - return (self_t&)*this; + self_t* s = static_cast<self_t*>(this); + s->methodsBitfield = 1 << static_cast<int>(method); + return *s; } template <typename... MethodArgs> self_t& methods(boost::beast::http::verb method, MethodArgs... args_method) { + self_t* s = static_cast<self_t*>(this); methods(args_method...); - ((self_t*)this)->methodsBitfield |= 1 << (int)method; - return (self_t&)*this; + s->methodsBitfield |= 1 << static_cast<int>(method); + return *s; } }; @@ -581,7 +586,7 @@ class Trie struct Node { unsigned ruleIndex{}; - std::array<unsigned, (int)ParamType::MAX> paramChildrens{}; + std::array<unsigned, static_cast<int>(ParamType::MAX)> paramChildrens{}; boost::container::flat_map<std::string, unsigned> children; bool isSimpleNode() const @@ -675,14 +680,15 @@ class Trie route_indexes.push_back(child->ruleIndex); } findRouteIndexes(req_url, route_indexes, child, - pos + fragment.size()); + pos + static_cast<unsigned>(fragment.size())); } else { if (req_url.compare(pos, fragment.size(), fragment) == 0) { - findRouteIndexes(req_url, route_indexes, child, - pos + fragment.size()); + findRouteIndexes( + req_url, route_indexes, child, + pos + static_cast<unsigned>(fragment.size())); } } } @@ -713,7 +719,7 @@ class Trie } }; - if (node->paramChildrens[(int)ParamType::INT]) + if (node->paramChildrens[static_cast<int>(ParamType::INT)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-') @@ -725,17 +731,18 @@ class Trie if (errno != ERANGE && eptr != req_url.data() + pos) { params->intParams.push_back(value); - auto ret = - find(req_url, - &nodes[node->paramChildrens[(int)ParamType::INT]], - eptr - req_url.data(), params); + auto ret = find( + req_url, + &nodes[node->paramChildrens[static_cast<int>( + ParamType::INT)]], + static_cast<unsigned>(eptr - req_url.data()), params); updateFound(ret); params->intParams.pop_back(); } } } - if (node->paramChildrens[(int)ParamType::UINT]) + if (node->paramChildrens[static_cast<int>(ParamType::UINT)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+') @@ -747,17 +754,18 @@ class Trie if (errno != ERANGE && eptr != req_url.data() + pos) { params->uintParams.push_back(value); - auto ret = - find(req_url, - &nodes[node->paramChildrens[(int)ParamType::UINT]], - eptr - req_url.data(), params); + auto ret = find( + req_url, + &nodes[node->paramChildrens[static_cast<int>( + ParamType::UINT)]], + static_cast<unsigned>(eptr - req_url.data()), params); updateFound(ret); params->uintParams.pop_back(); } } } - if (node->paramChildrens[(int)ParamType::DOUBLE]) + if (node->paramChildrens[static_cast<int>(ParamType::DOUBLE)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.') @@ -770,17 +778,18 @@ class Trie params->doubleParams.push_back(value); auto ret = find( req_url, - &nodes[node->paramChildrens[(int)ParamType::DOUBLE]], - eptr - req_url.data(), params); + &nodes[node->paramChildrens[static_cast<int>( + ParamType::DOUBLE)]], + static_cast<unsigned>(eptr - req_url.data()), params); updateFound(ret); params->doubleParams.pop_back(); } } } - if (node->paramChildrens[(int)ParamType::STRING]) + if (node->paramChildrens[static_cast<int>(ParamType::STRING)]) { - size_t epos = pos; + unsigned epos = pos; for (; epos < req_url.size(); epos++) { if (req_url[epos] == '/') @@ -791,26 +800,27 @@ class Trie { params->stringParams.emplace_back( req_url.substr(pos, epos - pos)); - auto ret = - find(req_url, - &nodes[node->paramChildrens[(int)ParamType::STRING]], - epos, params); + auto ret = find(req_url, + &nodes[node->paramChildrens[static_cast<int>( + ParamType::STRING)]], + epos, params); updateFound(ret); params->stringParams.pop_back(); } } - if (node->paramChildrens[(int)ParamType::PATH]) + if (node->paramChildrens[static_cast<int>(ParamType::PATH)]) { - size_t epos = req_url.size(); + unsigned epos = static_cast<unsigned>(req_url.size()); if (epos != pos) { params->stringParams.emplace_back( req_url.substr(pos, epos - pos)); - auto ret = find( - req_url, &nodes[node->paramChildrens[(int)ParamType::PATH]], - epos, params); + auto ret = find(req_url, + &nodes[node->paramChildrens[static_cast<int>( + ParamType::PATH)]], + epos, params); updateFound(ret); params->stringParams.pop_back(); } @@ -823,7 +833,9 @@ class Trie if (req_url.compare(pos, fragment.size(), fragment) == 0) { - auto ret = find(req_url, child, pos + fragment.size(), params); + auto ret = + find(req_url, child, + pos + static_cast<unsigned>(fragment.size()), params); updateFound(ret); } } @@ -858,12 +870,16 @@ class Trie { if (url.compare(i, x.name.size(), x.name) == 0) { - if (!nodes[idx].paramChildrens[(int)x.type]) + if (!nodes[idx] + .paramChildrens[static_cast<size_t>(x.type)]) { auto newNodeIdx = newNode(); - nodes[idx].paramChildrens[(int)x.type] = newNodeIdx; + nodes[idx] + .paramChildrens[static_cast<size_t>(x.type)] = + newNodeIdx; } - idx = nodes[idx].paramChildrens[(int)x.type]; + idx = nodes[idx] + .paramChildrens[static_cast<size_t>(x.type)]; i += x.name.size(); break; } @@ -888,15 +904,15 @@ class Trie } private: - void debugNodePrint(Node* n, int level) + void debugNodePrint(Node* n, unsigned level) { - for (int i = 0; i < (int)ParamType::MAX; i++) + for (size_t i = 0; i < static_cast<size_t>(ParamType::MAX); i++) { if (n->paramChildrens[i]) { BMCWEB_LOG_DEBUG << std::string( 2 * level, ' ') /*<< "("<<n->paramChildrens[i]<<") "*/; - switch ((ParamType)i) + switch (static_cast<ParamType>(i)) { case ParamType::INT: BMCWEB_LOG_DEBUG << "<int>"; @@ -950,7 +966,7 @@ class Trie unsigned newNode() { nodes.resize(nodes.size() + 1); - return nodes.size() - 1; + return static_cast<unsigned>(nodes.size() - 1); } std::vector<Node> nodes; @@ -991,13 +1007,14 @@ class Router std::unique_ptr<BaseRule> ruleObject) { rules.emplace_back(std::move(ruleObject)); - trie.add(rule, rules.size() - 1); + trie.add(rule, static_cast<unsigned>(rules.size() - 1)); // directory case: // request to `/about' url matches `/about/' rule if (rule.size() > 2 && rule.back() == '/') { - trie.add(rule.substr(0, rule.size() - 1), rules.size() - 1); + trie.add(rule.substr(0, rule.size() - 1), + static_cast<unsigned>(rules.size() - 1)); } } @@ -1056,12 +1073,12 @@ class Router return; } - if ((rules[ruleIndex]->getMethods() & (1 << (uint32_t)req.method())) == - 0) + if ((rules[ruleIndex]->getMethods() & + (1 << static_cast<uint32_t>(req.method()))) == 0) { BMCWEB_LOG_DEBUG << "Rule found but method mismatch: " << req.url << " with " << req.methodString() << "(" - << (uint32_t)req.method() << ") / " + << static_cast<uint32_t>(req.method()) << ") / " << rules[ruleIndex]->getMethods(); res = Response(boost::beast::http::status::not_found); res.end(); @@ -1069,7 +1086,7 @@ class Router } BMCWEB_LOG_DEBUG << "Matched rule (upgrade) '" << rules[ruleIndex]->rule - << "' " << (uint32_t)req.method() << " / " + << "' " << static_cast<uint32_t>(req.method()) << " / " << rules[ruleIndex]->getMethods(); // any uncaught exceptions become 500s @@ -1134,12 +1151,12 @@ class Router return; } - if ((rules[ruleIndex]->getMethods() & (1 << (uint32_t)req.method())) == - 0) + if ((rules[ruleIndex]->getMethods() & + (1 << static_cast<uint32_t>(req.method()))) == 0) { BMCWEB_LOG_DEBUG << "Rule found but method mismatch: " << req.url << " with " << req.methodString() << "(" - << (uint32_t)req.method() << ") / " + << static_cast<uint32_t>(req.method()) << ") / " << rules[ruleIndex]->getMethods(); res = Response(boost::beast::http::status::not_found); res.end(); @@ -1147,7 +1164,7 @@ class Router } BMCWEB_LOG_DEBUG << "Matched rule '" << rules[ruleIndex]->rule << "' " - << (uint32_t)req.method() << " / " + << static_cast<uint32_t>(req.method()) << " / " << rules[ruleIndex]->getMethods(); // any uncaught exceptions become 500s diff --git a/crow/include/crow/timer_queue.h b/crow/include/crow/timer_queue.h index bf1e084a00..556fdb3c30 100644 --- a/crow/include/crow/timer_queue.h +++ b/crow/include/crow/timer_queue.h @@ -22,10 +22,11 @@ class TimerQueue void cancel(int k) { - unsigned int index = static_cast<unsigned int>(k - step); - if (index < dq.size()) + int index = k - step; + + if (index < static_cast<int>(dq.size())) { - dq[index].second = nullptr; + dq[static_cast<size_t>(index)].second = nullptr; } } @@ -33,7 +34,7 @@ class TimerQueue { dq.push_back( std::make_pair(std::chrono::steady_clock::now(), std::move(f))); - int ret = step + dq.size() - 1; + int ret = step + static_cast<int>(dq.size()) - 1; BMCWEB_LOG_DEBUG << "timer add inside: " << this << ' ' << ret; return ret; diff --git a/crow/include/crow/utility.h b/crow/include/crow/utility.h index a07c0415af..5c7a7f6265 100644 --- a/crow/include/crow/utility.h +++ b/crow/include/crow/utility.h @@ -524,7 +524,7 @@ struct function_traits<std::function<r(Args...)>> }; inline static std::string base64encode( - const char* data, size_t size, + const uint8_t* data, size_t size, const char* key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") { @@ -533,36 +533,36 @@ inline static std::string base64encode( auto it = ret.begin(); while (size >= 3) { - *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; - *it++ = key[h | ((((unsigned char)*data) & 0xF0) >> 4)]; - h = (((unsigned char)*data++) & 0x0F) << 2; - *it++ = key[h | ((((unsigned char)*data) & 0xC0) >> 6)]; - *it++ = key[((unsigned char)*data++) & 0x3F]; + *it++ = key[(*data & 0xFC) >> 2]; + uint8_t h = static_cast<uint8_t>((*data++ & 0x03) << 4); + *it++ = key[h | ((*data & 0xF0) >> 4)]; + h = static_cast<uint8_t>((*data++ & 0x0F) << 2); + *it++ = key[h | ((*data & 0xC0) >> 6)]; + *it++ = key[*data++ & 0x3F]; size -= 3; } if (size == 1) { - *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; + *it++ = key[(*data & 0xFC) >> 2]; + uint8_t h = static_cast<uint8_t>((*data++ & 0x03) << 4); *it++ = key[h]; *it++ = '='; *it++ = '='; } else if (size == 2) { - *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; - *it++ = key[h | ((((unsigned char)*data) & 0xF0) >> 4)]; - h = (((unsigned char)*data++) & 0x0F) << 2; + *it++ = key[(*data & 0xFC) >> 2]; + uint8_t h = static_cast<uint8_t>((*data++ & 0x03) << 4); + *it++ = key[h | ((*data & 0xF0) >> 4)]; + h = static_cast<uint8_t>((*data++ & 0x0F) << 2); *it++ = key[h]; *it++ = '='; } return ret; } -inline static std::string base64encodeUrlsafe(const char* data, size_t size) +inline static std::string base64encodeUrlsafe(const uint8_t* data, size_t size) { return base64encode( data, size, @@ -669,10 +669,14 @@ inline bool base64Decode(const std::string_view input, std::string& output) inline void escapeHtml(std::string& data) { + if (data.empty()) + { + return; + } std::string buffer; - // less than 5% of characters should be larger, so reserve a buffer of the + // less than 10% of characters should be larger, so reserve a buffer of the // right size - buffer.reserve(data.size() * 1.05); + buffer.reserve(data.size() * 11 / 10); for (size_t pos = 0; pos != data.size(); ++pos) { switch (data[pos]) diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp index 1b82697f7a..cddafc8c06 100644 --- a/include/dbus_monitor.hpp +++ b/include/dbus_monitor.hpp @@ -150,7 +150,7 @@ template <typename... Middlewares> void requestRoutes(Crow<Middlewares...>& app) nlohmann::json::iterator paths = j.find("paths"); if (paths != j.end()) { - int interfaceCount = thisSession.interfaces.size(); + size_t interfaceCount = thisSession.interfaces.size(); if (interfaceCount == 0) { interfaceCount = 1; diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp index e45bb9ac50..947bc86eaf 100644 --- a/include/dbus_utility.hpp +++ b/include/dbus_utility.hpp @@ -48,8 +48,8 @@ inline bool getNthStringFromPath(const std::string& path, int index, std::string& result) { int count = 0; - auto first = path.begin(); - auto last = path.end(); + std::string::const_iterator first = path.begin(); + std::string::const_iterator last = path.end(); for (auto it = path.begin(); it < path.end(); it++) { // skip first character as it's either a leading slash or the first @@ -80,7 +80,8 @@ inline bool getNthStringFromPath(const std::string& path, int index, { first++; } - result = path.substr(first - path.begin(), last - first); + result = path.substr(static_cast<size_t>(first - path.begin()), + static_cast<size_t>(last - first)); return true; } diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index ab35bb2efc..e59692020b 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -570,8 +570,9 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type, { return -1; } - r = sd_bus_message_append_basic(m, argCode[0], - (void *)stringValue->c_str()); + r = sd_bus_message_append_basic( + m, argCode[0], + reinterpret_cast<const void *>(stringValue->c_str())); if (r < 0) { return r; @@ -737,13 +738,13 @@ int convertJsonToDbus(sd_bus_message *m, const std::string &arg_type, } nlohmann::json::const_iterator it = j->begin(); - for (const std::string &argCode : dbusArgSplit(arg_type)) + for (const std::string &argCode2 : dbusArgSplit(arg_type)) { if (it == j->end()) { return -1; } - r = convertJsonToDbus(m, argCode, *it); + r = convertJsonToDbus(m, argCode2, *it); if (r < 0) { return r; diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp index f211a29ec7..1469aef728 100644 --- a/include/pam_authenticate.hpp +++ b/include/pam_authenticate.hpp @@ -25,7 +25,7 @@ inline int pamFunctionConversation(int numMsg, const struct pam_message** msg, std::strcpy(pass, appPass); *resp = reinterpret_cast<pam_response*>( - calloc(numMsg, sizeof(struct pam_response))); + calloc(static_cast<size_t>(numMsg), sizeof(struct pam_response))); if (resp == nullptr) { diff --git a/include/persistent_data_middleware.hpp b/include/persistent_data_middleware.hpp index b384f02304..4cd75e889d 100644 --- a/include/persistent_data_middleware.hpp +++ b/include/persistent_data_middleware.hpp @@ -24,7 +24,7 @@ class Middleware { // todo(ed) should read this from a fixed location somewhere, not CWD static constexpr const char* filename = "bmcweb_persistent_data.json"; - int jsonRevision = 1; + uint64_t jsonRevision = 1; public: struct Context @@ -58,7 +58,7 @@ class Middleware void readData() { std::ifstream persistentFile(filename); - int fileRevision = 0; + uint64_t fileRevision = 0; if (persistentFile.is_open()) { // call with exceptions disabled diff --git a/include/sessions.hpp b/include/sessions.hpp index 6bc1c99f04..d55b1992d4 100644 --- a/include/sessions.hpp +++ b/include/sessions.hpp @@ -119,22 +119,22 @@ class SessionStore // https://www.owasp.org/index.php/Session_Management_Cheat_Sheet#Session_ID_Entropy std::string sessionToken; sessionToken.resize(20, '0'); - std::uniform_int_distribution<int> dist(0, alphanum.size() - 1); - for (int i = 0; i < sessionToken.size(); ++i) + std::uniform_int_distribution<size_t> dist(0, alphanum.size() - 1); + for (size_t i = 0; i < sessionToken.size(); ++i) { sessionToken[i] = alphanum[dist(rd)]; } // Only need csrf tokens for cookie based auth, token doesn't matter std::string csrfToken; csrfToken.resize(20, '0'); - for (int i = 0; i < csrfToken.size(); ++i) + for (size_t i = 0; i < csrfToken.size(); ++i) { csrfToken[i] = alphanum[dist(rd)]; } std::string uniqueId; uniqueId.resize(10, '0'); - for (int i = 0; i < uniqueId.size(); ++i) + for (size_t i = 0; i < uniqueId.size(); ++i) { uniqueId[i] = alphanum[dist(rd)]; } @@ -205,7 +205,7 @@ class SessionStore { return needWrite; } - int getTimeoutInSeconds() const + long getTimeoutInSeconds() const { return std::chrono::seconds(timeoutInMinutes).count(); }; diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp index 34a7c04409..133d40da5f 100644 --- a/include/ssl_key_handler.hpp +++ b/include/ssl_key_handler.hpp @@ -17,9 +17,7 @@ namespace ensuressl { static void initOpenssl(); -static void cleanupOpenssl(); -static EVP_PKEY *createRsaKey(); -static EVP_PKEY *createEcKey(); +static EVP_PKEY *createKey(); static void handleOpensslError(); inline bool verifyOpensslKeyCert(const std::string &filepath) @@ -110,7 +108,7 @@ inline void generateSslCertificate(const std::string &filepath) // EVP_PKEY *pRsaPrivKey = create_rsa_key(); std::cerr << "Generating EC key\n"; - EVP_PKEY *pRsaPrivKey = createEcKey(); + EVP_PKEY *pRsaPrivKey = createKey(); if (pRsaPrivKey != nullptr) { std::cerr << "Generating x509 Certificate\n"; @@ -177,9 +175,16 @@ inline void generateSslCertificate(const std::string &filepath) // cleanup_openssl(); } - -EVP_PKEY *createRsaKey() +EVP_PKEY *createKey() { + EVP_PKEY *pKey = NULL; + pKey = EVP_PKEY_new(); + if (pKey == nullptr) + { + handleOpensslError(); + return nullptr; + } +#if BMCWEB_RSA_KEY RSA *pRSA = NULL; #if OPENSSL_VERSION_NUMBER < 0x00908000L pRSA = RSA_generate_key(2048, RSA_3, NULL, NULL); @@ -187,60 +192,54 @@ EVP_PKEY *createRsaKey() RSA_generate_key_ex(pRSA, 2048, NULL, NULL); #endif - EVP_PKEY *pKey = EVP_PKEY_new(); - if ((pRSA != nullptr) && (pKey != nullptr) && - EVP_PKEY_assign_RSA(pKey, pRSA)) - { - /* pKey owns pRSA from now */ - if (RSA_check_key(pRSA) <= 0) - { - fprintf(stderr, "RSA_check_key failed.\n"); - handleOpensslError(); - EVP_PKEY_free(pKey); - pKey = NULL; - } - } - else + if ((pRSA != nullptr) || EVP_PKEY_assign_RSA(pKey, pRSA) != 1) { handleOpensslError(); if (pRSA != nullptr) { RSA_free(pRSA); - pRSA = NULL; } if (pKey != nullptr) { EVP_PKEY_free(pKey); - pKey = NULL; } + return nullptr; } - return pKey; -} -EVP_PKEY *createEcKey() -{ - EVP_PKEY *pKey = NULL; - int eccgrp = 0; - eccgrp = OBJ_txt2nid("prime256v1"); + /* pKey owns pRSA from now */ + if (RSA_check_key(pRSA) != 1) + { + fprintf(stderr, "RSA_check_key failed.\n"); + handleOpensslError(); + EVP_PKEY_free(pKey); + return nullptr; + } +#else + int eccgrp = OBJ_txt2nid("prime256v1"); EC_KEY *myecc = EC_KEY_new_by_curve_name(eccgrp); - if (myecc != nullptr) + if (myecc == nullptr) { - EC_KEY_set_asn1_flag(myecc, OPENSSL_EC_NAMED_CURVE); - EC_KEY_generate_key(myecc); - pKey = EVP_PKEY_new(); - if (pKey != nullptr) - { - if (EVP_PKEY_assign_EC_KEY(pKey, myecc)) - { - /* pKey owns pRSA from now */ - if (EC_KEY_check_key(myecc) <= 0) - { - fprintf(stderr, "EC_check_key failed.\n"); - } - } - } + handleOpensslError(); + return nullptr; + } + + EC_KEY_set_asn1_flag(myecc, OPENSSL_EC_NAMED_CURVE); + if (EC_KEY_generate_key(myecc) != 1) + { + handleOpensslError(); + EC_KEY_free(myecc); + return nullptr; + } + + if (EVP_PKEY_assign_EC_KEY(pKey, myecc) != 1) + { + handleOpensslError(); + EC_KEY_free(myecc); + return nullptr; } + +#endif return pKey; } @@ -253,16 +252,6 @@ void initOpenssl() #endif } -void cleanupOpenssl() -{ - CRYPTO_cleanup_all_ex_data(); - ERR_free_strings(); -#if OPENSSL_VERSION_NUMBER < 0x10100000L - ERR_remove_thread_state(0); -#endif - EVP_cleanup(); -} - void handleOpensslError() { ERR_print_errors_fp(stderr); diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp index 3b20c9fda8..15e1af4a06 100644 --- a/redfish-core/include/privileges.hpp +++ b/redfish-core/include/privileges.hpp @@ -34,10 +34,10 @@ constexpr std::array<const char*, 5> basePrivileges{ "Login", "ConfigureManager", "ConfigureComponents", "ConfigureSelf", "ConfigureUsers"}; -constexpr const int basePrivilegeCount = basePrivileges.size(); +constexpr const size_t basePrivilegeCount = basePrivileges.size(); /** @brief Max number of privileges per type */ -constexpr const int maxPrivilegeCount = 32; +constexpr const size_t maxPrivilegeCount = 32; /** @brief A vector of all privilege names and their indexes */ static const std::vector<std::string> privilegeNames{basePrivileges.begin(), @@ -96,7 +96,7 @@ class Privileges */ bool setSinglePrivilege(const char* privilege) { - for (int searchIndex = 0; searchIndex < privilegeNames.size(); + for (size_t searchIndex = 0; searchIndex < privilegeNames.size(); searchIndex++) { if (privilege == privilegeNames[searchIndex]) @@ -136,8 +136,8 @@ class Privileges { std::vector<const std::string*> activePrivileges; - int searchIndex = 0; - int endIndex = basePrivilegeCount; + size_t searchIndex = 0; + size_t endIndex = basePrivilegeCount; if (type == PrivilegeType::OEM) { searchIndex = basePrivilegeCount - 1; diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 476e03aff2..b9920187b7 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -302,7 +302,8 @@ inline void boost::container::flat_set<IPv4AddressData>::iterator, bool> it = ipv4_config.insert( - {objpath.first.str.substr(ipv4PathStart.size())}); + {objpath.first.str.substr(ipv4PathStart.size()), "", + "", "", "", "", LinkType::Local}); IPv4AddressData &ipv4_address = *it.first; for (auto &property : interface.second) { @@ -478,45 +479,6 @@ inline bool ipv4VerifyIpAndGetBitcount(const std::string &ip, } /** - * @brief Changes IPv4 address type property (Address, Gateway) - * - * @param[in] ifaceId Id of interface whose IP should be modified - * @param[in] ipIdx Index of IP in input array that should be modified - * @param[in] ipHash DBus Hash id of modified IP - * @param[in] name Name of field in JSON representation - * @param[in] newValue New value that should be written - * @param[io] asyncResp Response object that will be returned to client - * - * @return true if give IP is valid and has been sent do D-Bus, false - * otherwise - */ -inline void changeIPv4AddressProperty( - const std::string &ifaceId, int ipIdx, const std::string &ipHash, - const std::string &name, const std::string &newValue, - const std::shared_ptr<AsyncResp> asyncResp) -{ - auto callback = [asyncResp, ipIdx, name{std::string(name)}, - newValue{std::move(newValue)}]( - const boost::system::error_code ec) { - if (ec) - { - messages::internalError(asyncResp->res); - } - else - { - asyncResp->res.jsonValue["IPv4Addresses"][ipIdx][name] = newValue; - } - }; - - crow::connections::systemBus->async_method_call( - std::move(callback), "xyz.openbmc_project.Network", - "/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + ipHash, - "org.freedesktop.DBus.Properties", "Set", - "xyz.openbmc_project.Network.IP", name, - std::variant<std::string>(newValue)); -} - -/** * @brief Changes IPv4 address origin property * * @param[in] ifaceId Id of interface whose IP should be modified @@ -530,7 +492,7 @@ inline void changeIPv4AddressProperty( * @return true if give IP is valid and has been sent do D-Bus, false * otherwise */ -inline void changeIPv4Origin(const std::string &ifaceId, int ipIdx, +inline void changeIPv4Origin(const std::string &ifaceId, size_t ipIdx, const std::string &ipHash, const std::string &newValue, const std::string &newValueDbus, @@ -570,7 +532,8 @@ inline void changeIPv4Origin(const std::string &ifaceId, int ipIdx, * * @return None */ -inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx, +inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, + size_t ipIdx, const std::string &ipHash, const std::string &newValueStr, uint8_t &newValue, @@ -637,9 +600,8 @@ inline void deleteIPv4(const std::string &ifaceId, const std::string &ipHash, * * @return None */ -inline void createIPv4(const std::string &ifaceId, unsigned int ipIdx, - uint8_t subnetMask, const std::string &gateway, - const std::string &address, +inline void createIPv4(const std::string &ifaceId, uint8_t subnetMask, + const std::string &gateway, const std::string &address, std::shared_ptr<AsyncResp> asyncResp) { auto createIpHandler = [asyncResp](const boost::system::error_code ec) { @@ -1099,6 +1061,7 @@ class EthernetInterface : public Node if (gateway) { if (!ipv4VerifyIpAndGetBitcount(*gateway)) + { messages::propertyValueFormatError(asyncResp->res, *gateway, pathString + "/Gateway"); @@ -1198,8 +1161,7 @@ class EthernetInterface : public Node continue; } - createIPv4(ifaceId, entryIdx, prefixLength, *gateway, *address, - asyncResp); + createIPv4(ifaceId, entryIdx, *gateway, *address, asyncResp); nlohmann::json &ipv4AddressJson = asyncResp->res.jsonValue["IPv4Addresses"][entryIdx]; diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 61cbd9e03d..b07d6b1296 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -46,8 +46,8 @@ 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(), (const void **)&data, - &length); + ret = sd_journal_get_data(journal, field.data(), + reinterpret_cast<const void **>(&data), &length); if (ret < 0) { return ret; @@ -70,7 +70,7 @@ static int getJournalMetadata(sd_journal *journal, { return ret; } - contents = strtol(metadata.data(), nullptr, base); + contents = static_cast<int>(strtol(metadata.data(), nullptr, base)); return ret; } @@ -215,12 +215,12 @@ static bool getTimestampFromID(crow::Response &res, const std::string &entryID, { index = std::stoul(std::string(indexStr), &pos); } - catch (std::invalid_argument) + catch (std::invalid_argument &) { messages::resourceMissingAtURI(res, entryID); return false; } - catch (std::out_of_range) + catch (std::out_of_range &) { messages::resourceMissingAtURI(res, entryID); return false; @@ -237,12 +237,12 @@ static bool getTimestampFromID(crow::Response &res, const std::string &entryID, { timestamp = std::stoull(std::string(tsStr), &pos); } - catch (std::invalid_argument) + catch (std::invalid_argument &) { messages::resourceMissingAtURI(res, entryID); return false; } - catch (std::out_of_range) + catch (std::out_of_range &) { messages::resourceMissingAtURI(res, entryID); return false; @@ -382,8 +382,8 @@ static int fillEventLogEntryJson(const std::string &bmcLogEntryID, { continue; } - int argNum = std::strtoul(field.data(), nullptr, 10); - if (argNum == 0) + unsigned long argNum = std::strtoul(field.data(), nullptr, 10); + if (argNum == 0 || argNum > std::numeric_limits<size_t>::max()) { continue; } @@ -392,7 +392,7 @@ static int fillEventLogEntryJson(const std::string &bmcLogEntryID, // Make sure we have enough space in messageArgs if (argNum > messageArgs.size()) { - messageArgs.resize(argNum); + messageArgs.resize(static_cast<size_t>(argNum)); } messageArgs[argNum - 1] = std::string(field); } @@ -482,7 +482,7 @@ class EventLogEntryCollection : public Node std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( journalTmp, sd_journal_close); journalTmp = nullptr; - uint64_t entryCount = 0; + long entryCount = 0; SD_JOURNAL_FOREACH(journal.get()) { // Look for only journal entries that contain a REDFISH_MESSAGE_ID @@ -803,7 +803,7 @@ class BMCJournalLogEntryCollection : public Node std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( journalTmp, sd_journal_close); journalTmp = nullptr; - uint64_t entryCount = 0; + long entryCount = 0; SD_JOURNAL_FOREACH(journal.get()) { entryCount++; @@ -1094,7 +1094,7 @@ class CPULogEntry : public Node messages::internalError(asyncResp->res); return; } - const uint8_t logId = std::atoi(params[0].c_str()); + const int logId = std::atoi(params[0].c_str()); auto getStoredLogCallback = [asyncResp, logId]( const boost::system::error_code ec, const std::variant<std::string> &resp) { diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index f9c2f38072..0aa4478d28 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -785,10 +785,10 @@ static CreatePIDRet createPidInterface( for (auto& step : *steps) { double target; - double output; + double out; if (!redfish::json_util::readJson(step, response->res, "Target", - target, "Output", output)) + target, "Output", out)) { BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " @@ -796,7 +796,7 @@ static CreatePIDRet createPidInterface( return CreatePIDRet::fail; } readings.emplace_back(target); - outputs.emplace_back(output); + outputs.emplace_back(out); } output["Reading"] = std::move(readings); output["Output"] = std::move(outputs); diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp index b1df101462..78f1d8aecd 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -38,9 +38,8 @@ class Power : public Node } private: - std::initializer_list<const char*> typeList = { - "/xyz/openbmc_project/sensors/voltage", - "/xyz/openbmc_project/sensors/power"}; + std::vector<const char*> typeList = {"/xyz/openbmc_project/sensors/voltage", + "/xyz/openbmc_project/sensors/power"}; void doGet(crow::Response& res, const crow::Request& req, const std::vector<std::string>& params) override { diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index bbed0479a1..51895eedb9 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -49,7 +49,7 @@ class SensorsAsyncResp { public: SensorsAsyncResp(crow::Response& response, const std::string& chassisId, - const std::initializer_list<const char*> types, + const std::vector<const char*> types, const std::string& subNode) : res(response), chassisId(chassisId), types(types), chassisSubNode(subNode) @@ -539,11 +539,11 @@ void objectInterfacesToJson( auto interfaceProperties = interfacesDict.find(std::get<0>(p)); if (interfaceProperties != interfacesDict.end()) { - auto valueIt = interfaceProperties->second.find(std::get<1>(p)); - if (valueIt != interfaceProperties->second.end()) + auto valIt = interfaceProperties->second.find(std::get<1>(p)); + if (valIt != interfaceProperties->second.end()) { - const SensorVariant& valueVariant = valueIt->second; - nlohmann::json& valueIt = sensor_json[std::get<2>(p)]; + const SensorVariant& valueVariant = valIt->second; + nlohmann::json& jValueIt = sensor_json[std::get<2>(p)]; // Attempt to pull the int64 directly const int64_t* int64Value = std::get_if<int64_t>(&valueVariant); @@ -566,11 +566,11 @@ void objectInterfacesToJson( temp = temp * std::pow(10, scaleMultiplier); if (forceToInt) { - valueIt = static_cast<int64_t>(temp); + jValueIt = static_cast<int64_t>(temp); } else { - valueIt = temp; + jValueIt = temp; } } } @@ -985,7 +985,7 @@ void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp) */ void setSensorOverride(crow::Response& res, const crow::Request& req, const std::vector<std::string>& params, - const std::initializer_list<const char*> typeList, + const std::vector<const char*> typeList, const std::string& chassisSubNode) { diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp index f266c40c19..58e7cd445a 100644 --- a/redfish-core/lib/thermal.hpp +++ b/redfish-core/lib/thermal.hpp @@ -37,7 +37,7 @@ class Thermal : public Node } private: - std::initializer_list<const char*> typeList = { + std::vector<const char*> typeList = { "/xyz/openbmc_project/sensors/fan_tach", "/xyz/openbmc_project/sensors/temperature", "/xyz/openbmc_project/sensors/fan_pwm"}; |