From de8538282dfbb73212fa241638147a64bbe9cee5 Mon Sep 17 00:00:00 2001
From: Nick Hudson <nick.hudson@isode.com>
Date: Tue, 24 Mar 2015 16:56:21 +0000
Subject: Avoid potential double-adding of "lastConsumed" count to
 "bytesConsumed"

The code is currently doing
  bytesConsumed += lastConsumed;

inside one of the clauses in a while loop, and then the same operation
again when the while loop exits.  So there is a risk that the
"bytesConsumed" value will be too large.

In fact the only place the value of "bytesConsumed" is used is by some
code that checks whether it's greater than zero, so it would not be
problematic if the value were too large.

It seems worth fixing this in case future changes rely on the
"bytesConsumed" value being accurate.

Test-information:

inspection only

Change-Id: Ibd6fd01417afc4c4e030a5173bfba9a02980a757
signed-off-by:robert.williams@isode.com

diff --git a/src/com/isode/stroke/tls/java/JSSEContext.java b/src/com/isode/stroke/tls/java/JSSEContext.java
index 52edae1..da8316a 100644
--- a/src/com/isode/stroke/tls/java/JSSEContext.java
+++ b/src/com/isode/stroke/tls/java/JSSEContext.java
@@ -331,6 +331,9 @@ public class JSSEContext extends TLSContext {
                             /* It consumed some bytes, but perhaps not everything */
                             unwrapDone = (lastConsumed == bytesToUnwrap);
                         }
+                        // At this stage "lastConsumed" has already been added to 
+                        // "bytesConsumed"; don't do it again after exiting the while loop
+                        lastConsumed = 0;
                         break;
                     }
                 } while (!unwrapDone);
-- 
cgit v0.10.2-6-g49f6