From d13eca5d3c54284a12dca5dd4a44e837c4fa4919 Mon Sep 17 00:00:00 2001 From: Martin Dagarin Date: Tue, 29 Oct 2019 21:20:21 +0100 Subject: [PATCH] Added safety check len == 0 (#109) --- libfreefare/mifare_desfire_crypto.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index de2ff16..3d56699 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -69,6 +69,9 @@ xor(const uint8_t *ivect, uint8_t *data, const size_t len) void rol(uint8_t *data, const size_t len) { + if (len == 0) + return; + uint8_t first = data[0]; for (size_t i = 0; i < len - 1; i++) { data[i] = data[i + 1]; @@ -79,6 +82,9 @@ rol(uint8_t *data, const size_t len) void lsl(uint8_t *data, size_t len) { + if (len == 0) + return; + for (size_t n = 0; n < len - 1; n++) { data[n] = (data[n] << 1) | (data[n + 1] >> 7); }