Merge remote-tracking branch 'public/pr/2111' into development-proposed
diff --git a/ChangeLog b/ChangeLog
index c420b96..656688d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,9 @@
      invalidated keys of a lifetime of less than a 1s. Fixes #1968.
    * Fix failure in hmac_drbg in the benchmark sample application, when
      MBEDTLS_THREADING_C is defined. Found by TrinityTonic, #1095
+   * Fix a bug in the record decryption routine ssl_decrypt_buf()
+     which lead to accepting properly authenticated but improperly
+     padded records in case of CBC ciphersuites using Encrypt-then-MAC.
 
 Changes
    * Removed support for Yotta as a build tool.
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index ee7944b..bf43e88 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2307,13 +2307,13 @@
             correct = 0;
         }
         auth_done++;
-
-        /*
-         * Finally check the correct flag
-         */
-        if( correct == 0 )
-            return( MBEDTLS_ERR_SSL_INVALID_MAC );
     }
+
+    /*
+     * Finally check the correct flag
+     */
+    if( correct == 0 )
+        return( MBEDTLS_ERR_SSL_INVALID_MAC );
 #endif /* SSL_SOME_MODES_USE_MAC */
 
     /* Make extra sure authentication was performed, exactly once */