]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: add xmalloc0() helper 29405/head
authorLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2023 11:12:11 +0000 (13:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2023 13:02:26 +0000 (15:02 +0200)
src/boot/efi/measure.c
src/boot/efi/util.h

index 6f7282dc7db7ec731fa4baf7fed1a3207132ac48..f9aabb42be49f6e871094095e1339f7429625389 100644 (file)
@@ -25,8 +25,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(
         assert(description);
 
         desc_len = strsize16(description);
-        tcg_event = xmalloc(offsetof(TCG_PCR_EVENT, Event) + desc_len);
-        memzero(tcg_event, offsetof(TCG_PCR_EVENT, Event) + desc_len);
+        tcg_event = xmalloc0(offsetof(TCG_PCR_EVENT, Event) + desc_len);
         *tcg_event = (TCG_PCR_EVENT) {
                 .EventSize = desc_len,
                 .PCRIndex = pcrindex,
@@ -63,8 +62,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(
          * here. */
 
         desc_len = strsize16(description);
-        tcg_event = xmalloc(offsetof(EFI_TCG2_EVENT, Event) + desc_len);
-        memzero(tcg_event, offsetof(EFI_TCG2_EVENT, Event) + desc_len);
+        tcg_event = xmalloc0(offsetof(EFI_TCG2_EVENT, Event) + desc_len);
         *tcg_event = (EFI_TCG2_EVENT) {
                 .Size = offsetof(EFI_TCG2_EVENT, Event) + desc_len,
                 .Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
index de0c83ddb9b85296154f7749f3e2ba0edc862be2..10620dabcabcd41cfc7c6f931460e49f59f7b899 100644 (file)
@@ -35,6 +35,12 @@ static inline void *xmalloc(size_t size) {
         return p;
 }
 
+#define xmalloc0(size)                                  \
+        ({                                              \
+                size_t _size_ = (size);                 \
+                memzero(xmalloc(_size_), _size_);       \
+        })
+
 _malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_
 static inline void *xmalloc_multiply(size_t size, size_t n) {
         assert_se(!__builtin_mul_overflow(size, n, &size));