aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-11-29 15:31:06 +0000
committerlloyd <[email protected]>2010-11-29 15:31:06 +0000
commit04431bf49ddb336fc53715c2cade3814f5296172 (patch)
tree8103cc279fe9b4ae057715b05927643ffffc3e4c
parent006bb1af46d82386d0d2a8864b17918030a35da4 (diff)
Add checking here and avoid silent cast
-rw-r--r--src/filters/modes/mode_pad/mode_pad.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/filters/modes/mode_pad/mode_pad.cpp b/src/filters/modes/mode_pad/mode_pad.cpp
index 5d3a152d6..7809a122f 100644
--- a/src/filters/modes/mode_pad/mode_pad.cpp
+++ b/src/filters/modes/mode_pad/mode_pad.cpp
@@ -7,6 +7,7 @@
#include <botan/mode_pad.h>
#include <botan/exceptn.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -23,8 +24,14 @@ size_t BlockCipherModePaddingMethod::pad_bytes(size_t bs, size_t pos) const
*/
void PKCS7_Padding::pad(byte block[], size_t size, size_t position) const
{
+ const size_t bytes_remaining = size - position;
+ const byte pad_value = static_cast<byte>(bytes_remaining);
+
+ BOTAN_ASSERT_EQUAL(pad_value, bytes_remaining,
+ "Overflow in PKCS7_Padding");
+
for(size_t j = 0; j != size; ++j)
- block[j] = (size-position);
+ block[j] = pad_value;
}
/*