summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/slice/Ice/LocalException.ice31
-rw-r--r--cpp/src/Ice/Exception.cpp16
-rw-r--r--cpp/src/Ice/IdentityUtil.cpp40
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp23
-rw-r--r--cpp/src/Ice/ObjectAdapterI.h1
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp33
6 files changed, 130 insertions, 14 deletions
diff --git a/cpp/slice/Ice/LocalException.ice b/cpp/slice/Ice/LocalException.ice
index aaf3059a949..28ccf1e9c8a 100644
--- a/cpp/slice/Ice/LocalException.ice
+++ b/cpp/slice/Ice/LocalException.ice
@@ -181,6 +181,22 @@ local exception EndpointParseException
/**
*
* This exception is raised if there was an error while parsing a
+ * stringified identity.
+ *
+ **/
+local exception IdentityParseException
+{
+ /**
+ *
+ * The string which couldn't be parsed.
+ *
+ **/
+ string str;
+};
+
+/**
+ *
+ * This exception is raised if there was an error while parsing a
* stringified proxy.
*
**/
@@ -196,6 +212,21 @@ local exception ProxyParseException
/**
*
+ * This exception is raised if an illegal identity is encountered.
+ *
+ **/
+local exception IllegalIdentityException
+{
+ /**
+ *
+ * The illegal identity.
+ *
+ **/
+ Identity id;
+};
+
+/**
+ *
* This exception is raised if an operation call using a proxy
* resulted in a location forward to another proxy that doesn't
* match this proxy's identity.
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index 9ecde5040f7..7df89f3d7ac 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -116,6 +116,13 @@ Ice::EndpointParseException::ice_print(ostream& out) const
}
void
+Ice::IdentityParseException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nerror while parsing identity `" << str << "'";
+}
+
+void
Ice::ProxyParseException::ice_print(ostream& out) const
{
Exception::ice_print(out);
@@ -123,6 +130,13 @@ Ice::ProxyParseException::ice_print(ostream& out) const
}
void
+Ice::IllegalIdentityException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nillegal identity: `" << id << "'";
+}
+
+void
Ice::LocationForwardIdentityException::ice_print(ostream& out) const
{
Exception::ice_print(out);
@@ -132,7 +146,7 @@ Ice::LocationForwardIdentityException::ice_print(ostream& out) const
static void
printFailedRequestData(ostream& out, const RequestFailedException& ex)
{
- out << "\nidentity: " << identityToString(ex.id);
+ out << "\nidentity: " << ex.id;
out << "\nfacet: ";
vector<string>::const_iterator p = ex.facet.begin();
while(p != ex.facet.end())
diff --git a/cpp/src/Ice/IdentityUtil.cpp b/cpp/src/Ice/IdentityUtil.cpp
index bf089c9b8c0..3a419b7ca74 100644
--- a/cpp/src/Ice/IdentityUtil.cpp
+++ b/cpp/src/Ice/IdentityUtil.cpp
@@ -28,36 +28,54 @@ Ice::stringToIdentity(const string& s)
Identity ident;
//
- // Find unescaped separator
+ // Find unescaped separator.
//
- string::size_type slash = 0;
- while((slash = s.find('/', slash)) != string::npos)
+ string::size_type slash = string::npos, pos = 0;
+ while((pos = s.find('/', pos)) != string::npos)
{
- if(slash == 0 || s[slash - 1] != '\\')
+ if(pos == 0 || s[pos - 1] != '\\')
{
- break;
+ if(slash == string::npos)
+ {
+ slash = pos;
+ }
+ else
+ {
+ //
+ // Extra unescaped slash found.
+ //
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
+ }
}
- slash++;
+ pos++;
}
if(slash == string::npos)
{
- if(!decodeString(s, 0, 0, ident.name))
+ if(!decodeString(s, 0, s.size(), ident.name))
{
- throw SyscallException(__FILE__, __LINE__);
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
}
}
else
{
if(!decodeString(s, 0, slash, ident.category))
{
- throw SyscallException(__FILE__, __LINE__);
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
}
if(slash + 1 < s.size())
{
- if(!decodeString(s, slash + 1, 0, ident.name))
+ if(!decodeString(s, slash + 1, s.size(), ident.name))
{
- throw SyscallException(__FILE__, __LINE__);
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
}
}
}
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 7ac6e051fe8..2fde6a7d55a 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -180,6 +180,8 @@ Ice::ObjectAdapterI::add(const ObjectPtr& object, const Identity& ident)
throw ex;
}
+ checkIdentity(ident);
+
_activeServantMapHint = _activeServantMap.insert(_activeServantMapHint, make_pair(ident, object));
return newProxy(ident);
@@ -217,6 +219,8 @@ Ice::ObjectAdapterI::remove(const Identity& ident)
throw ex;
}
+ checkIdentity(ident);
+
_activeServantMap.erase(ident);
_activeServantMapHint = _activeServantMap.end();
}
@@ -320,6 +324,8 @@ Ice::ObjectAdapterI::findServantLocator(const string& prefix)
ObjectPtr
Ice::ObjectAdapterI::identityToServant(const Identity& ident)
{
+ checkIdentity(ident);
+
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(_activeServantMapHint != _activeServantMap.end())
@@ -352,6 +358,8 @@ Ice::ObjectAdapterI::proxyToServant(const ObjectPrx& proxy)
ObjectPrx
Ice::ObjectAdapterI::createProxy(const Identity& ident)
{
+ checkIdentity(ident);
+
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_instance)
@@ -367,6 +375,8 @@ Ice::ObjectAdapterI::createProxy(const Identity& ident)
ObjectPrx
Ice::ObjectAdapterI::createDirectProxy(const Identity& ident)
{
+ checkIdentity(ident);
+
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_instance)
@@ -382,6 +392,8 @@ Ice::ObjectAdapterI::createDirectProxy(const Identity& ident)
ObjectPrx
Ice::ObjectAdapterI::createReverseProxy(const Identity& ident)
{
+ checkIdentity(ident);
+
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_instance)
@@ -650,6 +662,17 @@ Ice::ObjectAdapterI::newDirectProxy(const Identity& ident) const
}
+void
+Ice::ObjectAdapterI::checkIdentity(const Identity& ident)
+{
+ if(ident.name.size() == 0)
+ {
+ IllegalIdentityException e(__FILE__, __LINE__);
+ e.id = ident;
+ throw e;
+ }
+}
+
bool
Ice::ObjectAdapterI::isLocal(const ObjectPrx& proxy) const
{
diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h
index dd686cde2f0..7a0ef3e89d1 100644
--- a/cpp/src/Ice/ObjectAdapterI.h
+++ b/cpp/src/Ice/ObjectAdapterI.h
@@ -74,6 +74,7 @@ private:
ObjectPrx newProxy(const Identity&) const;
ObjectPrx newDirectProxy(const Identity&) const;
+ static void checkIdentity(const Identity&);
bool isLocal(const ObjectPrx&) const;
::IceInternal::InstancePtr _instance;
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index c46708a4cdc..6353bc9993f 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -167,10 +167,39 @@ IceInternal::ReferenceFactory::create(const string& str)
throw ex;
}
+ //
+ // Parsing the identity may raise IdentityParseException.
+ //
Identity ident = stringToIdentity(idstr);
- if(ident.name.empty() && ident.category.empty())
+
+ if(ident.name.empty())
{
- return 0;
+ //
+ // An identity with an empty name and a non-empty
+ // category is illegal.
+ //
+ if(!ident.category.empty())
+ {
+ IllegalIdentityException e(__FILE__, __LINE__);
+ e.id = ident;
+ throw e;
+ }
+ //
+ // Treat a stringified proxy containing two double
+ // quotes ("") the same as an empty string, i.e.,
+ // a null proxy, but only if nothing follows the
+ // quotes.
+ //
+ else if(s.find_first_not_of(delim, end) != string::npos)
+ {
+ ProxyParseException ex(__FILE__, __LINE__);
+ ex.str = str;
+ throw ex;
+ }
+ else
+ {
+ return 0;
+ }
}
vector<string> facet;