Add limit for report name length
Added limit for report name length, parametrized with
max-report-name-length option, because we cannot
remove reports with too long report name.
Tested:
- Confirmed that report with name length equal to 4096
cannot be generated via bmcweb (POST
redfish/v1/TelemetryService/MetricReportDefinitions
fails with code 500)
- Confirmed that report with name length equal to 4095
can be generated and removed via bmcweb
- Added unit-test that test that report with name
length equal to max-report-name-length + 1 cannot
be generated
- Added unit-test that test that report with name
length equal to max-report-name-length can
be generated
Change-Id: I6868320f831079af903f3624d1beff648059e351
Signed-off-by: Karol Niczyj <karol.niczyj@intel.com>
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 9ea6026..24087c3 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -28,6 +28,10 @@
"MaxReports", size_t{}, sdbusplus::vtable::property_::const_,
[](const auto&) { return maxReports; });
dbusIface.register_property_r(
+ "MaxReportNameLength", size_t{},
+ sdbusplus::vtable::property_::const_,
+ [](const auto&) { return maxReportNameLength; });
+ dbusIface.register_property_r(
"MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_,
[](const auto&) -> uint64_t { return minInterval.count(); });
@@ -57,6 +61,16 @@
reports.end());
}
+void ReportManager::verifyReportNameLength(const std::string& reportName)
+{
+ if (reportName.length() > maxReportNameLength)
+ {
+ throw sdbusplus::exception::SdBusError(
+ static_cast<int>(std::errc::invalid_argument),
+ "Report name exceed maximum length");
+ }
+}
+
void ReportManager::verifyAddReport(const std::string& reportName,
const std::string& reportingType,
std::chrono::milliseconds interval,
@@ -69,6 +83,8 @@
"Reached maximal report count");
}
+ verifyReportNameLength(reportName);
+
for (const auto& report : reports)
{
if (report->getName() == reportName)
diff --git a/src/report_manager.hpp b/src/report_manager.hpp
index bb4d395..e66a614 100644
--- a/src/report_manager.hpp
+++ b/src/report_manager.hpp
@@ -5,6 +5,8 @@
#include "interfaces/report_factory.hpp"
#include "interfaces/report_manager.hpp"
+#include <systemd/sd-bus-protocol.h>
+
#include <sdbusplus/asio/object_server.hpp>
#include <chrono>
@@ -36,6 +38,7 @@
std::unique_ptr<sdbusplus::asio::dbus_interface> reportManagerIface;
std::vector<std::unique_ptr<interfaces::Report>> reports;
+ void verifyReportNameLength(const std::string& reportName);
void verifyAddReport(const std::string& reportName,
const std::string& reportingType,
std::chrono::milliseconds interval,
@@ -57,6 +60,8 @@
public:
static constexpr size_t maxReports{TELEMETRY_MAX_REPORTS};
static constexpr size_t maxReadingParams{TELEMETRY_MAX_READING_PARAMS};
+ static constexpr size_t maxReportNameLength{
+ TELEMETRY_MAX_REPORT_NAME_LENGTH};
static constexpr std::chrono::milliseconds minInterval{
TELEMETRY_MIN_INTERVAL};
static constexpr const char* reportManagerIfaceName =