diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/IceUtil/StringUtil.h | 5 | ||||
-rw-r--r-- | cpp/src/Ice/DefaultsAndOverrides.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/EndpointFactoryManager.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 26 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/OpaqueEndpointI.cpp | 50 | ||||
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.cpp | 63 | ||||
-rw-r--r-- | cpp/src/Ice/TcpEndpointI.cpp | 34 | ||||
-rw-r--r-- | cpp/src/Ice/UdpEndpointI.cpp | 58 | ||||
-rw-r--r-- | cpp/src/IcePatch2Lib/Util.cpp | 9 | ||||
-rw-r--r-- | cpp/src/IceSSL/EndpointI.cpp | 34 | ||||
-rw-r--r-- | cpp/src/IceUtil/StringUtil.cpp | 63 | ||||
-rw-r--r-- | cpp/test/Ice/proxy/AllTests.cpp | 21 |
13 files changed, 256 insertions, 113 deletions
diff --git a/cpp/include/IceUtil/StringUtil.h b/cpp/include/IceUtil/StringUtil.h index 4efd077dfb7..cb39efc02e5 100644 --- a/cpp/include/IceUtil/StringUtil.h +++ b/cpp/include/IceUtil/StringUtil.h @@ -23,9 +23,10 @@ namespace IceUtilInternal ICE_UTIL_API std::string escapeString(const std::string&, const std::string&); // -// Remove escape sequences added by escapeString. +// Remove escape sequences added by escapeString. Throws IllegalArgumentException +// for an invalid input string. // -ICE_UTIL_API bool unescapeString(const std::string&, std::string::size_type, std::string::size_type, std::string&); +ICE_UTIL_API std::string unescapeString(const std::string&, std::string::size_type, std::string::size_type); // // Split a string using the given delimiters. Considers single and double quotes; diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index 81572b0ec68..587b9d79717 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -86,7 +86,7 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro else { EndpointSelectionTypeParseException ex(__FILE__, __LINE__); - ex.str = value; + ex.str = "illegal value `" + value + "'; expected `Random' or `Ordered'"; throw ex; } diff --git a/cpp/src/Ice/EndpointFactoryManager.cpp b/cpp/src/Ice/EndpointFactoryManager.cpp index 0c1e823712e..516f9dbbc44 100644 --- a/cpp/src/Ice/EndpointFactoryManager.cpp +++ b/cpp/src/Ice/EndpointFactoryManager.cpp @@ -72,7 +72,7 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint) if(beg == string::npos) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "value has no non-whitespace characters"; throw ex; } diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 24540c65491..f42191c8246 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -406,7 +406,7 @@ IceInternal::Instance::stringToIdentity(const string& s) const // Extra unescaped slash found. // IdentityParseException ex(__FILE__, __LINE__); - ex.str = s; + ex.str = "unescaped backslash in identity `" + s + "'"; throw ex; } } @@ -415,27 +415,39 @@ IceInternal::Instance::stringToIdentity(const string& s) const if(slash == string::npos) { - if(!IceUtilInternal::unescapeString(s, 0, s.size(), ident.name)) + try + { + ident.name = IceUtilInternal::unescapeString(s, 0, s.size()); + } + catch(const IceUtil::IllegalArgumentException& e) { IdentityParseException ex(__FILE__, __LINE__); - ex.str = s; + ex.str = "invalid identity name `" + s + "': " + e.reason(); throw ex; } } else { - if(!IceUtilInternal::unescapeString(s, 0, slash, ident.category)) + try + { + ident.category = IceUtilInternal::unescapeString(s, 0, slash); + } + catch(const IceUtil::IllegalArgumentException& e) { IdentityParseException ex(__FILE__, __LINE__); - ex.str = s; + ex.str = "invalid category in identity `" + s + "': " + e.reason(); throw ex; } if(slash + 1 < s.size()) { - if(!IceUtilInternal::unescapeString(s, slash + 1, s.size(), ident.name)) + try + { + ident.name = IceUtilInternal::unescapeString(s, slash + 1, s.size()); + } + catch(const IceUtil::IllegalArgumentException& e) { IdentityParseException ex(__FILE__, __LINE__); - ex.str = s; + ex.str = "invalid name in identity `" + s + "': " + e.reason(); throw ex; } } diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 69363ee91db..2c1ad771e36 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -1213,7 +1213,7 @@ Ice::ObjectAdapterI::parseEndpoints(const string& endpts, bool oaEndpoints) cons if(endp == 0) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = s; + ex.str = "invalid object adapter endpoint `" + s + "'"; throw ex; } endpoints.push_back(endp); diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp index 9960872df1c..e4b1ee75215 100644 --- a/cpp/src/Ice/OpaqueEndpointI.cpp +++ b/cpp/src/Ice/OpaqueEndpointI.cpp @@ -46,7 +46,7 @@ IceInternal::OpaqueEndpointI::OpaqueEndpointI(const string& str) if(option.length() != 2 || option[0] != '-') { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ex.str = "expected an endpoint option but found `" + option + "' in endpoint `opaque " + str + "'"; throw ex; } @@ -67,16 +67,34 @@ IceInternal::OpaqueEndpointI::OpaqueEndpointI(const string& str) { case 't': { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -t option in endpoint `opaque " + str + "'"; + throw ex; + } istringstream p(argument); Ice::Int t; - if(!(p >> t) || !p.eof() || t < 0 || t > 65535) + if(!(p >> t) || !p.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ex.str = "invalid timeout value `" + argument + "' in endpoint `opaque " + str + "'"; + throw ex; + } + else if(t < 0 || t > 65535) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "timeout value `" + argument + "' out of range in endpoint `opaque " + str + "'"; throw ex; } _type = static_cast<Ice::Short>(t); ++topt; + if(topt > 1) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "multiple -t options in endpoint `opaque " + str + "'"; + throw ex; + } break; } @@ -85,7 +103,7 @@ IceInternal::OpaqueEndpointI::OpaqueEndpointI(const string& str) if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ex.str = "no argument provided for -v option in endpoint `opaque " + str + "'"; throw ex; } for(string::size_type i = 0; i < argument.size(); ++i) @@ -93,27 +111,43 @@ IceInternal::OpaqueEndpointI::OpaqueEndpointI(const string& str) if(!Base64::isBase64(argument[i])) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ostringstream ostr; + ostr << "invalid base64 character `" << argument[i] << "' (ordinal " << (int)argument[i] + << ") in endpoint `opaque " << str << "'"; + ex.str = ostr.str(); throw ex; } } const_cast<vector<Byte>&>(_rawBytes) = Base64::decode(argument); ++vopt; + if(vopt > 1) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "multiple -v options in endpoint `opaque " + str + "'"; + throw ex; + } break; } default: { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ex.str = "invalid option `" + option + "' in endpoint `opaque " + str + "'"; throw ex; } } } - if(topt != 1 || vopt != 1) + + if(topt != 1) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no -t option in endpoint `opaque " + str + "'"; + throw ex; + } + if(vopt != 1) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "opaque " + str; + ex.str = "no -v option in endpoint `opaque " + str + "'"; throw ex; } } diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index fb6c0d0327d..2881e3953a3 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -110,7 +110,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(beg == string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "no non-whitespace characters found in `" + s + "'"; throw ex; } @@ -123,7 +123,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(end == string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "mismatched quotes around identity in `" + s + "'"; throw ex; } else if(end == 0) @@ -145,7 +145,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(beg == end) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "no identity in `" + s + "'"; throw ex; } @@ -174,7 +174,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP else if(s.find_first_not_of(delim, end) != string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "invalid characters after identity in `" + s + "'"; throw ex; } else @@ -216,7 +216,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(option.length() != 2 || option[0] != '-') { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "expected a proxy option but found `" + option + "' in `" + s + "'"; throw ex; } @@ -236,7 +236,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(end == string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "mismatched quotes around value for " + option + " option in `" + s + "'"; throw ex; } else if(end == 0) @@ -268,14 +268,18 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "no argument provided for -f option in `" + s + "'"; throw ex; } - if(!IceUtilInternal::unescapeString(argument, 0, argument.size(), facet)) + try + { + facet = IceUtilInternal::unescapeString(argument, 0, argument.size()); + } + catch(const IceUtil::IllegalArgumentException& e) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "invalid facet in `" + s + "': " + e.reason(); throw ex; } @@ -288,7 +292,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -t option in `" + s + "'"; throw ex; } mode = Reference::ModeTwoway; @@ -300,7 +304,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -o option in `" + s + "'"; throw ex; } mode = Reference::ModeOneway; @@ -312,7 +316,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -O option in `" + s + "'"; throw ex; } mode = Reference::ModeBatchOneway; @@ -324,7 +328,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -d option in `" + s + "'"; throw ex; } mode = Reference::ModeDatagram; @@ -336,7 +340,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -D option in `" + s + "'"; throw ex; } mode = Reference::ModeBatchDatagram; @@ -348,7 +352,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(!argument.empty()) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unexpected argument `" + argument + "' provided for -s option in `" + s + "'"; throw ex; } secure = true; @@ -358,7 +362,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP default: { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "unknown option `" + option + "' in `" + s + "'"; throw ex; } } @@ -439,8 +443,9 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP } if(endpoints.size() == 0) { + assert(!unknownEndpoints.empty()); EndpointParseException ex(__FILE__, __LINE__); - ex.str = unknownEndpoints.front(); + ex.str = "invalid endpoint `" + unknownEndpoints.front() + "' in `" + s + "'"; throw ex; } else if(unknownEndpoints.size() != 0 && @@ -464,7 +469,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(beg == string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "missing adapter id in `" + s + "'"; throw ex; } @@ -473,7 +478,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(end == string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "mismatched quotes around adapter id in `" + s + "'"; throw ex; } else if(end == 0) @@ -496,14 +501,24 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(end != string::npos && s.find_first_not_of(delim, end) != string::npos) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "invalid trailing characters after `" + s.substr(0, end + 1) + "' in `" + s + "'"; throw ex; } - if(!IceUtilInternal::unescapeString(adapterstr, 0, adapterstr.size(), adapter) || adapter.size() == 0) + try + { + adapter = IceUtilInternal::unescapeString(adapterstr, 0, adapterstr.size()); + } + catch(const IceUtil::IllegalArgumentException& e) + { + ProxyParseException ex(__FILE__, __LINE__); + ex.str = "invalid adapter id in `" + s + "': " + e.reason(); + throw ex; + } + if(adapter.size() == 0) { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "empty adapter id in `" + s + "'"; throw ex; } @@ -515,7 +530,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP default: { ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; + ex.str = "malformed proxy `" + s + "'"; throw ex; } } @@ -771,7 +786,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, else { EndpointSelectionTypeParseException ex(__FILE__, __LINE__); - ex.str = type; + ex.str = "illegal value `" + type + "'; expected `Random' or `Ordered'"; throw ex; } } diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index c8e027b4ffb..3ac47c875bc 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -62,7 +62,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin if(option.length() != 2 || option[0] != '-') { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "expected an endpoint option but found `" + option + "' in endpoint `tcp " + str + "'"; throw ex; } @@ -90,7 +90,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "no argument provided for -h option in endpoint `tcp " + str + "'"; throw ex; } const_cast<string&>(_host) = argument; @@ -99,11 +99,23 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin case 'p': { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -p option in endpoint `tcp " + str + "'"; + throw ex; + } istringstream p(argument); - if(!(p >> const_cast<Int&>(_port)) || !p.eof() || _port < 0 || _port > 65535) + if(!(p >> const_cast<Int&>(_port)) || !p.eof()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "invalid port value `" + argument + "' in endpoint `tcp " + str + "'"; + throw ex; + } + else if(_port < 0 || _port > 65535) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "port value `" + argument + "' out of range in endpoint `tcp " + str + "'"; throw ex; } break; @@ -111,11 +123,17 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin case 't': { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -t option in endpoint `tcp " + str + "'"; + throw ex; + } istringstream t(argument); if(!(t >> const_cast<Int&>(_timeout)) || !t.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "invalid timeout value `" + argument + "' in endpoint `tcp " + str + "'"; throw ex; } break; @@ -126,7 +144,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin if(!argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "unexpected argument `" + argument + "' provided for -z option in `tcp " + str + "'"; throw ex; } const_cast<bool&>(_compress) = true; @@ -136,7 +154,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin default: { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "unknown option `" + option + "' in `tcp " + str + "'"; throw ex; } } @@ -155,7 +173,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(const InstancePtr& instance, const strin else { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "tcp " + str; + ex.str = "`-h *' not valid for proxy endpoint `tcp " + str + "'"; throw ex; } } diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 6d0ed5e6989..9119ece31f9 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -74,7 +74,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(option[0] != '-') { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "expected an endpoint option but found `" + option + "' in endpoint `udp " + str + "'"; throw ex; } @@ -89,7 +89,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(end == string::npos) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "mismatched quotes around `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } else @@ -117,7 +117,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "no argument provided for -v option in endpoint `udp " + str + "'"; throw ex; } @@ -125,7 +125,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(pos == string::npos) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "malformed protocol version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } string majorStr = argument.substr(0, pos); @@ -136,7 +136,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!(majStr >> majVersion) || !majStr.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "invalid protocol major version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } @@ -145,14 +145,14 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!(minStr >> minVersion) || !minStr.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "invalid protocol minor version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "range error in protocol version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } @@ -174,7 +174,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "no argument provided for -e option in endpoint `udp " + str + "'"; throw ex; } string::size_type pos = argument.find('.'); @@ -186,7 +186,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!(majStr >> majVersion) || !majStr.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "invalid encoding major version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } @@ -195,14 +195,14 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!(minStr >> minVersion) || !minStr.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "invalid encoding minor version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "range error in encoding version `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } @@ -224,18 +224,30 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "no argument provided for -h option in endpoint `udp " + str + "'"; throw ex; } const_cast<string&>(_host) = argument; } else if(option == "-p") { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -p option in endpoint `udp " + str + "'"; + throw ex; + } istringstream p(argument); - if(!(p >> const_cast<Int&>(_port)) || !p.eof() || _port < 0 || _port > 65535) + if(!(p >> const_cast<Int&>(_port)) || !p.eof()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "invalid port value `" + argument + "' in endpoint `udp " + str + "'"; + throw ex; + } + else if(_port < 0 || _port > 65535) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "port value `" + argument + "' out of range in endpoint `udp " + str + "'"; throw ex; } } @@ -244,7 +256,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "unexpected argument `" + argument + "' provided for -c option in `udp " + str + "'"; throw ex; } const_cast<bool&>(_connect) = true; @@ -254,7 +266,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(!argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "unexpected argument `" + argument + "' provided for -z option in `udp " + str + "'"; throw ex; } const_cast<bool&>(_compress) = true; @@ -264,25 +276,31 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "no argument provided for --interface option in endpoint `udp " + str + "'"; throw ex; } const_cast<string&>(_mcastInterface) = argument; } else if(option == "--ttl") { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for --ttl option in endpoint `udp " + str + "'"; + throw ex; + } istringstream p(argument); if(!(p >> const_cast<Int&>(_mcastTtl)) || !p.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "invalid TTL value `" + argument + "' in endpoint `udp " + str + "'"; throw ex; } } else { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "unknown option `" + option + "' in `udp " + str + "'"; throw ex; } } @@ -300,7 +318,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin else { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "udp " + str; + ex.str = "`-h *' not valid for proxy endpoint `udp " + str + "'"; throw ex; } } diff --git a/cpp/src/IcePatch2Lib/Util.cpp b/cpp/src/IcePatch2Lib/Util.cpp index 0aeb63fbbf6..0d73f1df4c4 100644 --- a/cpp/src/IcePatch2Lib/Util.cpp +++ b/cpp/src/IcePatch2Lib/Util.cpp @@ -150,7 +150,14 @@ IcePatch2::readFileInfo(FILE* fp, FileInfo& info) string s; getline(is, s, '\t'); - IceUtilInternal::unescapeString(s, 0, s.size(), info.path); + try + { + info.path = IceUtilInternal::unescapeString(s, 0, s.size()); + } + catch(const IceUtil::IllegalArgumentException& ex) + { + throw ex.reason(); + } getline(is, s, '\t'); info.checksum = stringToBytes(s); diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp index 01e32c9c47a..d1b699d4859 100644 --- a/cpp/src/IceSSL/EndpointI.cpp +++ b/cpp/src/IceSSL/EndpointI.cpp @@ -62,7 +62,7 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo if(option.length() != 2 || option[0] != '-') { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "expected an endpoint option but found `" + option + "' in endpoint `ssl " + str + "'"; throw ex; } @@ -90,7 +90,7 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo if(argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "no argument provided for -h option in endpoint `ssl " + str + "'"; throw ex; } const_cast<string&>(_host) = argument; @@ -99,11 +99,23 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo case 'p': { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -p option in endpoint `ssl " + str + "'"; + throw ex; + } istringstream p(argument); - if(!(p >> const_cast<Int&>(_port)) || !p.eof() || _port < 0 || _port > 65535) + if(!(p >> const_cast<Int&>(_port)) || !p.eof()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "invalid port value `" + argument + "' in endpoint `ssl " + str + "'"; + throw ex; + } + else if(_port < 0 || _port > 65535) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "port value `" + argument + "' out of range in endpoint `ssl " + str + "'"; throw ex; } break; @@ -111,11 +123,17 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo case 't': { + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -t option in endpoint `ssl " + str + "'"; + throw ex; + } istringstream t(argument); if(!(t >> const_cast<Int&>(_timeout)) || !t.eof()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "invalid timeout value `" + argument + "' in endpoint `ssl " + str + "'"; throw ex; } break; @@ -126,7 +144,7 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo if(!argument.empty()) { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "unexpected argument `" + argument + "' provided for -z option in `ssl " + str + "'"; throw ex; } const_cast<bool&>(_compress) = true; @@ -136,7 +154,7 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo default: { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "unknown option `" + option + "' in `ssl " + str + "'"; throw ex; } } @@ -155,7 +173,7 @@ IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, boo else { EndpointParseException ex(__FILE__, __LINE__); - ex.str = "ssl " + str; + ex.str = "`-h *' not valid for proxy endpoint `ssl " + str + "'"; throw ex; } } diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp index 3c65ad42dd7..296c5dd9cf6 100644 --- a/cpp/src/IceUtil/StringUtil.cpp +++ b/cpp/src/IceUtil/StringUtil.cpp @@ -161,11 +161,22 @@ namespace { char -checkChar(char c) +checkChar(const string& s, string::size_type pos) { - if(!(static_cast<unsigned char>(c) >= 32 && static_cast<unsigned char>(c) <= 126)) + unsigned char c = static_cast<unsigned char>(s[pos]); + if(!(c >= 32 && c <= 126)) { - throw IllegalArgumentException(__FILE__, __LINE__, "illegal input character"); + ostringstream ostr; + if(pos > 0) + { + ostr << "character after `" << s.substr(0, pos) << "'"; + } + else + { + ostr << "first character"; + } + ostr << " is not a printable ASCII character (ordinal " << (int)c << ")"; + throw IllegalArgumentException(__FILE__, __LINE__, ostr.str()); } return c; } @@ -186,13 +197,13 @@ decodeChar(const string& s, string::size_type start, string::size_type end, stri if(s[start] != '\\') { - c = checkChar(s[start++]); + c = checkChar(s, start++); } else { if(start + 1 == end) { - throw IllegalArgumentException(__FILE__, __LINE__, "trailing backslash in argument"); + throw IllegalArgumentException(__FILE__, __LINE__, "trailing backslash"); } switch(s[++start]) { @@ -242,7 +253,7 @@ decodeChar(const string& s, string::size_type start, string::size_type end, stri case '6': case '7': { - int oct = 0; + int val = 0; for(int j = 0; j < 3 && start < end; ++j) { int charVal = s[start++] - '0'; @@ -251,18 +262,20 @@ decodeChar(const string& s, string::size_type start, string::size_type end, stri --start; break; } - oct = oct * 8 + charVal; + val = val * 8 + charVal; } - if(oct > 255) + if(val > 255) { - throw IllegalArgumentException(__FILE__, __LINE__, "octal value out of range"); + ostringstream ostr; + ostr << "octal value \\" << oct << val << dec << " (" << val << ") is out of range"; + throw IllegalArgumentException(__FILE__, __LINE__, ostr.str()); } - c = (char)oct; + c = (char)val; break; } default: { - c = checkChar(s[start++]); + c = checkChar(s, start++); break; } } @@ -289,30 +302,16 @@ decodeString(const string& s, string::size_type start, string::size_type end, st // // Remove escape sequences added by escapeString. // -bool -IceUtilInternal::unescapeString(const string& s, string::size_type start, string::size_type end, string& result) +string +IceUtilInternal::unescapeString(const string& s, string::size_type start, string::size_type end) { - if(end > s.size()) - { - throw IllegalArgumentException(__FILE__, __LINE__, "end offset must be <= s.size()"); - } - if(start > end) - { - throw IllegalArgumentException(__FILE__, __LINE__, "start offset must <= end offset"); - } + assert(start <= end && end <= s.size()); + string result; result.reserve(end - start); - - try - { - result.clear(); - decodeString(s, start, end, result); - return true; - } - catch(...) - { - return false; - } + result.clear(); + decodeString(s, start, end, result); + return result; } bool diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index 7165938a046..271f849d39a 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -93,6 +93,27 @@ allTests(const Ice::CommunicatorPtr& communicator) test(b1->ice_getIdentity().name == "test" && b1->ice_getIdentity().category == "category" && b1->ice_getAdapterId().empty()); + b1 = communicator->stringToProxy(""); + test(!b1); + b1 = communicator->stringToProxy("\"\""); + test(!b1); + try + { + b1 = communicator->stringToProxy("\"\" test"); // Invalid trailing characters. + test(false); + } + catch(const Ice::ProxyParseException&) + { + } + try + { + b1 = communicator->stringToProxy("test:"); // Missing endpoint. + test(false); + } + catch(const Ice::EndpointParseException&) + { + } + b1 = communicator->stringToProxy("test@adapter"); test(b1->ice_getIdentity().name == "test" && b1->ice_getIdentity().category.empty() && b1->ice_getAdapterId() == "adapter"); |