Description: konversation: out-of-bounds read on a heap-allocated array
 Konversation's Blowfish ECB encryption support assumes incoming blocks
 to be the expected 12 bytes. The lack of a sanity-check for the actual
 size can cause a denial of service (crash) and an information leak of
 up to 11 bytes due to an out-of-bounds read on a heap-allocated array.
Author: Eike Hein <hein@kde.org>
Origin: upstream, https://www.kde.org/info/security/advisory-20140923-1.txt 
Reviewed-by: Jonathan Riddell
Last-Update: 2014-11-04
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/cipher.cpp
+++ b/src/cipher.cpp
@@ -353,8 +353,12 @@
         }
         else
         {
+        // ECB Blowfish encodes in blocks of 12 chars, so anything else is malformed input
+        if ((temp.length() % 12) != 0)
+            return cipherText;
+
             temp = b64ToByte(temp);
-            while((temp.length() % 8) != 0) temp.append('\0');
+            while ((temp.length() % 8) != 0) temp.append('\0');
         }
 
         QCA::Direction dir = (direction) ? QCA::Encode : QCA::Decode;
@@ -362,11 +366,17 @@
         QByteArray temp2 = cipher.update(QCA::MemoryRegion(temp)).toByteArray();
         temp2 += cipher.final().toByteArray();
 
-        if(!cipher.ok())
+        if (!cipher.ok())
             return cipherText;
 
-        if(direction)
+        if (direction)
+        {
+            // Sanity check
+            if ((temp2.length() % 8) != 0)
+                return cipherText;
+
             temp2 = byteToB64(temp2);
+        }
 
         return temp2;
     }

