From f1652acba26dc5e27c711a41e522ef86de2dbdf4 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Wed, 11 Mar 2020 19:05:57 +0100 Subject: [PATCH] Avoid memmove() call when buffers are already the same. (#935) This completes the work started in commit fbe3eb265fc1e93c74bf6110615176d1fb432b04 --- src/libsodium/crypto_secretbox/crypto_secretbox_easy.c | 4 ++-- .../xchacha20poly1305/secretbox_xchacha20poly1305.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c index b1203849..12132a2a 100644 --- a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +++ b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c @@ -101,9 +101,9 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c, if (m == NULL) { return 0; } - if (((uintptr_t) c >= (uintptr_t) m && + if (((uintptr_t) c > (uintptr_t) m && (uintptr_t) c - (uintptr_t) m < clen) || - ((uintptr_t) m >= (uintptr_t) c && + ((uintptr_t) m > (uintptr_t) c && (uintptr_t) m - (uintptr_t) c < clen)) { /* LCOV_EXCL_LINE */ memmove(m, c, clen); c = m; diff --git a/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c b/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c index e76167d2..d012b13b 100644 --- a/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +++ b/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c @@ -108,9 +108,9 @@ crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m, if (m == NULL) { return 0; } - if (((uintptr_t) c >= (uintptr_t) m && + if (((uintptr_t) c > (uintptr_t) m && (uintptr_t) c - (uintptr_t) m < clen) || - ((uintptr_t) m >= (uintptr_t) c && + ((uintptr_t) m > (uintptr_t) c && (uintptr_t) m - (uintptr_t) c < clen)) { /* LCOV_EXCL_LINE */ memmove(m, c, clen); c = m;