Remove regex match pattern from object_server
Removed regex from object_server to avoid crash on std::regex_match
function when input string is very long. It is known bug in gcc that
std::regex crashes with stack overflow when matching long lines.
Removed verifying path and interface from add_interface method because
both are verified in sd_bus_add_object_vtable function.
Checking return code of sd_bus_add_object_vtable is covered in
017a19da5f67a74daedf4d63111569902d4764e6 commit thanks to Waqar Hameed
<waqarh@axis.com>.
Tested:
- Added new path longer than 1024 signs with success
- Verified if add_interface return invalid argument on invalid path
and interface
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
Change-Id: I11481fa724f04ae441e5d247a120882b272b3b6e
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index f163208..cf3cb80 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -19,7 +19,6 @@
#include <list>
#include <optional>
-#include <regex>
#include <set>
namespace sdbusplus
@@ -27,9 +26,8 @@
namespace asio
{
-constexpr const char* PropertyNamePattern = "[a-zA-Z0-9_]+";
-constexpr const char* PathPattern = "(/[a-zA-Z0-9_]+)+";
-constexpr const char* InterfaceNamePattern = "[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)+";
+constexpr const char* PropertyNameAllowedCharacters =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
class callback
{
@@ -386,7 +384,8 @@
{
return false;
}
- if (!std::regex_match(name, std::regex(PropertyNamePattern)))
+ if (name.find_first_not_of(PropertyNameAllowedCharacters) !=
+ std::string::npos)
{
return false;
}
@@ -426,7 +425,8 @@
{
return false;
}
- if (!std::regex_match(name, std::regex(PropertyNamePattern)))
+ if (name.find_first_not_of(PropertyNameAllowedCharacters) !=
+ std::string::npos)
{
return false;
}
@@ -535,7 +535,8 @@
{
return false;
}
- if (!std::regex_match(name, std::regex(PropertyNamePattern)))
+ if (name.find_first_not_of(PropertyNameAllowedCharacters) !=
+ std::string::npos)
{
return false;
}
@@ -829,11 +830,6 @@
std::shared_ptr<dbus_interface> add_interface(const std::string& path,
const std::string& name)
{
- if (!std::regex_match(path, std::regex(PathPattern)) ||
- !std::regex_match(name, std::regex(InterfaceNamePattern)))
- {
- throw exception::SdBusError(EINVAL, "Invalid path or interface");
- }
auto dbusIface = std::make_shared<dbus_interface>(conn_, path, name);
interfaces_.emplace_back(dbusIface);
return dbusIface;