From 3b6891b0d0b7a6b80e82aad03e615237165fd31a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 6 Apr 2015 21:55:20 +0200 Subject: [PATCH] Fix integer overflow if no max resumption time is specified by client and server. Fixes SMACK-653. --- .../org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 4f28dc633..86dea74da 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -1612,7 +1612,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { throw new StreamManagementException.StreamManagementNotEnabledException(); } // Remove the listener after max. 12 hours - final int removeAfterSeconds = Math.min(getMaxSmResumptionTime() + 60, 12 * 60 * 60); + final int removeAfterSeconds = Math.min(getMaxSmResumptionTime(), 12 * 60 * 60); schedule(new Runnable() { @Override public void run() { @@ -1703,8 +1703,13 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { /** * Get the maximum resumption time in seconds after which a managed stream can be resumed. + *

+ * This method will return {@link Integer#MAX_VALUE} if neither the client nor the server specify a maximum + * resumption time. Be aware of integer overflows when using this value, e.g. do not add arbitrary values to it + * without checking for overflows before. + *

* - * @return the maximum resumption time in seconds. + * @return the maximum resumption time in seconds or {@link Integer#MAX_VALUE} if none set. */ public int getMaxSmResumptionTime() { int clientResumptionTime = smClientMaxResumptionTime > 0 ? smClientMaxResumptionTime : Integer.MAX_VALUE;