dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0018-UTIL-Add-SAFEALIGN_COPY_UINT8_CHECK.patch

ecf709
From 4aecf8a2d3962d962da1e2f98b0bb3b84a8ae536 Mon Sep 17 00:00:00 2001
ecf709
From: Jakub Hrozek <jhrozek@redhat.com>
ecf709
Date: Thu, 23 Feb 2017 20:55:05 +0100
ecf709
Subject: [PATCH 18/36] UTIL: Add SAFEALIGN_COPY_UINT8_CHECK
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
This macro will be used later in the KCM code
ecf709
ecf709
Reviewed-by: Michal Židek <mzidek@redhat.com>
ecf709
Reviewed-by: Simo Sorce <simo@redhat.com>
ecf709
---
ecf709
 src/util/util_safealign.h | 6 ++++++
ecf709
 1 file changed, 6 insertions(+)
ecf709
ecf709
diff --git a/src/util/util_safealign.h b/src/util/util_safealign.h
ecf709
index 0d9a579cdbfafc30bf2d0a6ad2651c71428ebd93..57f04a17d4a38300b959c1593d756b351ebd89e8 100644
ecf709
--- a/src/util/util_safealign.h
ecf709
+++ b/src/util/util_safealign.h
ecf709
@@ -130,6 +130,12 @@ safealign_memcpy(void *dest, const void *src, size_t n, size_t *counter)
ecf709
     safealign_memcpy(dest, src, srclen, pctr); \
ecf709
 } while(0)
ecf709
 
ecf709
+#define SAFEALIGN_COPY_UINT8_CHECK(dest, src, len, pctr) do { \
ecf709
+    if ((*(pctr) + sizeof(uint8_t)) > (len) || \
ecf709
+        SIZE_T_OVERFLOW(*(pctr), sizeof(uint8_t))) { return EINVAL; } \
ecf709
+    safealign_memcpy(dest, src, sizeof(uint8_t), pctr); \
ecf709
+} while(0)
ecf709
+
ecf709
 /* Aliases for backward compatibility. */
ecf709
 #define SAFEALIGN_SET_VALUE SAFEALIGN_SETMEM_VALUE
ecf709
 #define SAFEALIGN_SET_INT64 SAFEALIGN_SETMEM_INT64
ecf709
-- 
ecf709
2.9.3
ecf709