diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2016-09-23 13:41:53 +0200 |
---|---|---|
committer | Lukas Slebodnik <lslebodn@redhat.com> | 2017-03-14 13:31:47 +0100 |
commit | cab319e2db4b3d85dcadbfdf4c88939df103892e (patch) | |
tree | 70b0740e8059bb6abd512e47faf325b3ff6b60ba | |
parent | 606015a4f71d8ee809347188667d268f73110483 (diff) | |
download | sssd-cab319e2db4b3d85dcadbfdf4c88939df103892e.tar.gz sssd-cab319e2db4b3d85dcadbfdf4c88939df103892e.tar.xz sssd-cab319e2db4b3d85dcadbfdf4c88939df103892e.zip |
UTIL: Add a new macro SAFEALIGN_MEMCPY_CHECK
We will use it later in the KCM server
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
-rw-r--r-- | src/util/util_safealign.h | 6 |
1 files changed, 6 insertions, 0 deletions
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 |