summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-10-12 00:13:40 +0000
committerMark Spruiell <mes@zeroc.com>2002-10-12 00:13:40 +0000
commit17173387a237b2da8f61780d269e25a78f317cf5 (patch)
tree732320c904414575b4e64383dd6f9235bc571c6b /java/src
parentbug fix (diff)
downloadice-17173387a237b2da8f61780d269e25a78f317cf5.tar.bz2
ice-17173387a237b2da8f61780d269e25a78f317cf5.tar.xz
ice-17173387a237b2da8f61780d269e25a78f317cf5.zip
validate identities
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Ice/ObjectAdapterI.java35
-rw-r--r--java/src/Ice/Util.java40
-rw-r--r--java/src/IceInternal/ReferenceFactory.java33
3 files changed, 95 insertions, 13 deletions
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index fc9f1af84ca..6d8c8c597aa 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -173,6 +173,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
throw e;
}
+ checkIdentity(ident);
+
//
// Create a copy of the Identity argument, in case the caller
// reuses it
@@ -215,6 +217,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
throw e;
}
+ checkIdentity(ident);
+
_activeServantMap.remove(ident);
}
@@ -264,6 +268,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
public synchronized Ice.Object
identityToServant(Identity ident)
{
+ checkIdentity(ident);
+
return (Ice.Object)_activeServantMap.get(ident);
}
@@ -284,6 +290,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
throw e;
}
+ checkIdentity(ident);
+
return newProxy(ident);
}
@@ -297,6 +305,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
throw e;
}
+ checkIdentity(ident);
+
return newDirectProxy(ident);
}
@@ -310,6 +320,8 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
throw e;
}
+ checkIdentity(ident);
+
//
// Create a reference and return a reverse proxy for this reference.
//
@@ -580,6 +592,29 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
return _instance.proxyFactory().referenceToProxy(reference);
}
+ private static void
+ checkIdentity(Identity ident)
+ {
+ if(ident.name == null || ident.name.length() == 0)
+ {
+ IllegalIdentityException e = new IllegalIdentityException();
+ try
+ {
+ e.id = (Identity)ident.clone();
+ }
+ catch(CloneNotSupportedException ex)
+ {
+ assert(false);
+ }
+ throw e;
+ }
+
+ if(ident.category == null)
+ {
+ ident.category = "";
+ }
+ }
+
public boolean
isLocal(ObjectPrx proxy)
{
diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java
index 071aabd9872..48cec80b5ec 100644
--- a/java/src/Ice/Util.java
+++ b/java/src/Ice/Util.java
@@ -109,24 +109,38 @@ public final class Util
Identity ident = new Identity();
//
- // Find unescaped separator
+ // Find unescaped separator.
//
- int slash = 0;
- while((slash = s.indexOf('/', slash)) != -1)
+ int slash = -1, pos = 0;
+ while((pos = s.indexOf('/', pos)) != -1)
{
- if(slash == 0 || s.charAt(slash - 1) != '\\')
+ if(pos == 0 || s.charAt(pos - 1) != '\\')
{
- break;
+ if(slash == -1)
+ {
+ slash = pos;
+ }
+ else
+ {
+ //
+ // Extra unescaped slash found.
+ //
+ IdentityParseException ex = new IdentityParseException();
+ ex.str = s;
+ throw ex;
+ }
}
- slash++;
+ pos++;
}
if(slash == -1)
{
StringHolder token = new StringHolder();
- if(!IceInternal.StringUtil.decodeString(s, 0, 0, token))
+ if(!IceInternal.StringUtil.decodeString(s, 0, s.length(), token))
{
- throw new SyscallException();
+ IdentityParseException ex = new IdentityParseException();
+ ex.str = s;
+ throw ex;
}
ident.category = "";
ident.name = token.value;
@@ -136,14 +150,18 @@ public final class Util
StringHolder token = new StringHolder();
if(!IceInternal.StringUtil.decodeString(s, 0, slash, token))
{
- throw new SyscallException();
+ IdentityParseException ex = new IdentityParseException();
+ ex.str = s;
+ throw ex;
}
ident.category = token.value;
if(slash + 1 < s.length())
{
- if(!IceInternal.StringUtil.decodeString(s, slash + 1, 0, token))
+ if(!IceInternal.StringUtil.decodeString(s, slash + 1, s.length(), token))
{
- throw new SyscallException();
+ IdentityParseException ex = new IdentityParseException();
+ ex.str = s;
+ throw ex;
}
ident.name = token.value;
}
diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java
index 7815d149b0d..a944eb8b353 100644
--- a/java/src/IceInternal/ReferenceFactory.java
+++ b/java/src/IceInternal/ReferenceFactory.java
@@ -128,10 +128,39 @@ public final class ReferenceFactory
throw e;
}
+ //
+ // Parsing the identity may raise IdentityParseException.
+ //
Ice.Identity ident = Ice.Util.stringToIdentity(idstr);
- if(ident.name.length() == 0 && ident.category.length() == 0)
+
+ if(ident.name.length() == 0)
{
- return null;
+ //
+ // An identity with an empty name and a non-empty
+ // category is illegal.
+ //
+ if(ident.category.length() > 0)
+ {
+ Ice.IllegalIdentityException e = new Ice.IllegalIdentityException();
+ 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(StringUtil.findFirstNotOf(s, delim, end) != -1)
+ {
+ Ice.ProxyParseException e = new Ice.ProxyParseException();
+ e.str = s;
+ throw e;
+ }
+ else
+ {
+ return null;
+ }
}
java.util.ArrayList facet = new java.util.ArrayList();