Blob Blame History Raw
From 4aecf8a2d3962d962da1e2f98b0bb3b84a8ae536 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Thu, 23 Feb 2017 20:55:05 +0100
Subject: [PATCH 18/36] UTIL: Add SAFEALIGN_COPY_UINT8_CHECK
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This macro will be used later in the KCM code

Reviewed-by: Michal Židek <mzidek@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
---
 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 0d9a579cdbfafc30bf2d0a6ad2651c71428ebd93..57f04a17d4a38300b959c1593d756b351ebd89e8 100644
--- a/src/util/util_safealign.h
+++ b/src/util/util_safealign.h
@@ -130,6 +130,12 @@ safealign_memcpy(void *dest, const void *src, size_t n, size_t *counter)
     safealign_memcpy(dest, src, srclen, pctr); \
 } while(0)
 
+#define SAFEALIGN_COPY_UINT8_CHECK(dest, src, len, pctr) do { \
+    if ((*(pctr) + sizeof(uint8_t)) > (len) || \
+        SIZE_T_OVERFLOW(*(pctr), sizeof(uint8_t))) { return EINVAL; } \
+    safealign_memcpy(dest, src, sizeof(uint8_t), pctr); \
+} while(0)
+
 /* Aliases for backward compatibility. */
 #define SAFEALIGN_SET_VALUE SAFEALIGN_SETMEM_VALUE
 #define SAFEALIGN_SET_INT64 SAFEALIGN_SETMEM_INT64
-- 
2.9.3