From c02f9061a111e11db8439c224ba59589a430c964 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 30 Oct 2024 16:22:47 +0100 Subject: [PATCH 1/2] Validate default timeouts --- cpp/src/Ice/DefaultsAndOverrides.cpp | 16 ++++++++++++ .../src/Ice/Internal/DefaultsAndOverrides.cs | 25 +++++++++++++------ .../com/zeroc/Ice/DefaultsAndOverrides.java | 17 +++++++++---- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index 4cde22cc46b..c59b1caa409 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -65,8 +65,24 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro const_cast(defaultInvocationTimeout) = chrono::milliseconds(properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout")); + if (defaultInvocationTimeout.count() < 1 && defaultInvocationTimeout.count() != -1) + { + throw InitializationException( + __FILE__, + __LINE__, + "invalid value for Ice.Default.InvocationTimeout " + to_string(defaultInvocationTimeout.count()) + "'"); + } + const_cast(defaultLocatorCacheTimeout) = chrono::seconds(properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); + if (defaultLocatorCacheTimeout.count() < -1) + { + throw InitializationException( + __FILE__, + __LINE__, + "invalid value for Ice.Default.LocatorCacheTimeout '" + to_string(defaultLocatorCacheTimeout.count()) + + "'"); + } const_cast(defaultPreferSecure) = properties->getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; diff --git a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs index 095d654f194..954a0b4cecf 100644 --- a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs +++ b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs @@ -80,16 +80,27 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) throw new ParseException($"illegal value '{val}' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); } - defaultLocatorCacheTimeout = TimeSpan.FromSeconds( - properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); - defaultInvocationTimeout = TimeSpan.FromMilliseconds( - properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout")); + { + int value = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); + if (value < -1) + { + throw new InitializationException($"invalid value for Ice.Default.LocatorCacheTimeout '{value}'"); + } + defaultLocatorCacheTimeout = TimeSpan.FromSeconds(value); + } + + { + int value = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); + if (value < 1 && value != -1) + { + throw new InitializationException($"invalid value for Ice.Default.InvocationTimeout '{value}'"); + } + defaultInvocationTimeout = TimeSpan.FromMilliseconds(value); + } defaultPreferSecure = properties.getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; - val = properties.getPropertyWithDefault( - "Ice.Default.EncodingVersion", - Ice.Util.encodingVersionToString(Ice.Util.currentEncoding)); + val = properties.getIceProperty("Ice.Default.EncodingVersion"); defaultEncoding = Ice.Util.stringToEncodingVersion(val); Protocol.checkSupportedEncoding(defaultEncoding); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java index a835051b0a5..62bd08c7321 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java @@ -67,12 +67,19 @@ final class DefaultsAndOverrides { + "' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); } - defaultLocatorCacheTimeout = - Duration.ofSeconds( - properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); + intValue = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); + if (intValue < -1) { + throw new InitializationException( + "invalid value for Ice.Default.LocatorCacheTimeout '" + intValue + "'"); + } + defaultLocatorCacheTimeout = Duration.ofSeconds(intValue); - defaultInvocationTimeout = - Duration.ofMillis(properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout")); + intValue = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); + if (intValue < 1 && intValue != -1) { + throw new InitializationException( + "invalid value for Ice.Default.InvocationTimeout '" + intValue + "'"); + } + defaultInvocationTimeout = Duration.ofMillis(intValue); defaultPreferSecure = properties.getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; From ed200e8dc91898091b1e00294570d9efd9b7b573 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 30 Oct 2024 18:51:13 +0100 Subject: [PATCH 2/2] Review fixes --- cpp/src/Ice/DefaultsAndOverrides.cpp | 9 ++++----- csharp/src/Ice/Internal/DefaultsAndOverrides.cs | 4 ++-- .../main/java/com/zeroc/Ice/DefaultsAndOverrides.java | 4 ++-- js/src/Ice/DefaultsAndOverrides.js | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index c59b1caa409..d7494f0a93d 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -67,21 +67,20 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro chrono::milliseconds(properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout")); if (defaultInvocationTimeout.count() < 1 && defaultInvocationTimeout.count() != -1) { - throw InitializationException( + throw InitializationException{ __FILE__, __LINE__, - "invalid value for Ice.Default.InvocationTimeout " + to_string(defaultInvocationTimeout.count()) + "'"); + "invalid value for Ice.Default.InvocationTimeout: " + to_string(defaultInvocationTimeout.count())}; } const_cast(defaultLocatorCacheTimeout) = chrono::seconds(properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); if (defaultLocatorCacheTimeout.count() < -1) { - throw InitializationException( + throw InitializationException{ __FILE__, __LINE__, - "invalid value for Ice.Default.LocatorCacheTimeout '" + to_string(defaultLocatorCacheTimeout.count()) + - "'"); + "invalid value for Ice.Default.LocatorCacheTimeout: " + to_string(defaultLocatorCacheTimeout.count())}; } const_cast(defaultPreferSecure) = properties->getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; diff --git a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs index 954a0b4cecf..47eae4650e7 100644 --- a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs +++ b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs @@ -84,7 +84,7 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) int value = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); if (value < -1) { - throw new InitializationException($"invalid value for Ice.Default.LocatorCacheTimeout '{value}'"); + throw new InitializationException($"invalid value for Ice.Default.LocatorCacheTimeout: {value}"); } defaultLocatorCacheTimeout = TimeSpan.FromSeconds(value); } @@ -93,7 +93,7 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) int value = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); if (value < 1 && value != -1) { - throw new InitializationException($"invalid value for Ice.Default.InvocationTimeout '{value}'"); + throw new InitializationException($"invalid value for Ice.Default.InvocationTimeout: {value}"); } defaultInvocationTimeout = TimeSpan.FromMilliseconds(value); } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java index 62bd08c7321..b9258709ff8 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java @@ -70,14 +70,14 @@ final class DefaultsAndOverrides { intValue = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); if (intValue < -1) { throw new InitializationException( - "invalid value for Ice.Default.LocatorCacheTimeout '" + intValue + "'"); + "invalid value for Ice.Default.LocatorCacheTimeout: " + intValue); } defaultLocatorCacheTimeout = Duration.ofSeconds(intValue); intValue = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); if (intValue < 1 && intValue != -1) { throw new InitializationException( - "invalid value for Ice.Default.InvocationTimeout '" + intValue + "'"); + "invalid value for Ice.Default.InvocationTimeout: " + intValue); } defaultInvocationTimeout = Duration.ofMillis(intValue); diff --git a/js/src/Ice/DefaultsAndOverrides.js b/js/src/Ice/DefaultsAndOverrides.js index 191f67d1721..34170aa4d9d 100644 --- a/js/src/Ice/DefaultsAndOverrides.js +++ b/js/src/Ice/DefaultsAndOverrides.js @@ -37,14 +37,14 @@ export class DefaultsAndOverrides { this.defaultLocatorCacheTimeout = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); if (this.defaultLocatorCacheTimeout < -1) { throw new InitializationException( - `invalid value for Ice.Default.LocatorCacheTimeout '${this.defaultLocatorCacheTimeout}'`, + `invalid value for Ice.Default.LocatorCacheTimeout: ${this.defaultLocatorCacheTimeout}`, ); } this.defaultInvocationTimeout = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); if (this.defaultInvocationTimeout < 1 && this.defaultInvocationTimeout !== -1) { throw new InitializationException( - `invalid value for Ice.Default.InvocationTimeout '${this.defaultInvocationTimeout}'`, + `invalid value for Ice.Default.InvocationTimeout: ${this.defaultInvocationTimeout}`, ); }