From cab319e2db4b3d85dcadbfdf4c88939df103892e Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 23 Sep 2016 13:41:53 +0200 Subject: UTIL: Add a new macro SAFEALIGN_MEMCPY_CHECK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will use it later in the KCM server Reviewed-by: Pavel Březina Reviewed-by: Lukáš Slebodník --- src/util/util_safealign.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/util_safealign.h b/src/util/util_safealign.h index a2cd4dd0d..0d9a579cd 100644 --- a/src/util/util_safealign.h +++ b/src/util/util_safealign.h @@ -124,6 +124,12 @@ safealign_memcpy(void *dest, const void *src, size_t n, size_t *counter) safealign_memcpy(dest, CV_MACRO_val, sizeof(char) * length, pctr); \ } while(0) +#define SAFEALIGN_MEMCPY_CHECK(dest, src, srclen, len, pctr) do { \ + if ((*(pctr) + srclen) > (len) || \ + SIZE_T_OVERFLOW(*(pctr), srclen)) { return EINVAL; } \ + safealign_memcpy(dest, src, srclen, pctr); \ +} while(0) + /* Aliases for backward compatibility. */ #define SAFEALIGN_SET_VALUE SAFEALIGN_SETMEM_VALUE #define SAFEALIGN_SET_INT64 SAFEALIGN_SETMEM_INT64 -- cgit