Bomb if we get a node name with a "/" in it

This commit is contained in:
Josh Faust 2009-10-02 21:29:52 +00:00
parent d9aafe2f86
commit 88804b4947
3 changed files with 22 additions and 0 deletions

View File

@ -33,6 +33,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <list> #include <list>
#include <stdexcept>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
@ -163,6 +164,14 @@ typedef boost::shared_ptr<XMLRPCManager> XMLRPCManagerPtr;
class PollManager; class PollManager;
typedef boost::shared_ptr<PollManager> PollManagerPtr; typedef boost::shared_ptr<PollManager> PollManagerPtr;
class Exception : public std::runtime_error
{
public:
Exception(const std::string& what)
: std::runtime_error(what)
{}
};
} }
#endif #endif

View File

@ -33,6 +33,14 @@
namespace ros namespace ros
{ {
class InvalidNodeNameException : public ros::Exception
{
public:
InvalidNodeNameException(const std::string& name, const std::string& reason)
: Exception("Invalid node name [" + name + "]: " + reason)
{}
};
/** /**
* \brief Contains functions which provide information about this process' ROS node * \brief Contains functions which provide information about this process' ROS node
*/ */

View File

@ -98,6 +98,11 @@ void init(const std::string& name, const M_string& remappings, uint32_t options)
// It must be done before we resolve g_name, because otherwise the name will not get remapped. // It must be done before we resolve g_name, because otherwise the name will not get remapped.
names::init(remappings); names::init(remappings);
if (g_name.find("/") != std::string::npos)
{
throw InvalidNodeNameException(g_name, "node names cannot contain /");
}
g_name = names::resolve(g_namespace, g_name); g_name = names::resolve(g_namespace, g_name);
if (options & init_options::AnonymousName && !disable_anon) if (options & init_options::AnonymousName && !disable_anon)