systemd/0583-tpm2-in-validator-functions-return-false-instead-of-.patch

42 lines
1.6 KiB
Diff
Raw Normal View History

From e498b6a8d2f75e56e725faa1b57b9c5552efc812 Mon Sep 17 00:00:00 2001
From: Dan Streetman <ddstreet@ieee.org>
Date: Mon, 21 Aug 2023 10:48:20 -0400
Subject: [PATCH] tpm2: in validator functions, return false instead of assert
failure
(cherry picked from commit 064ac95d81b9ab6a6eb8849cacce928015d44e5b)
Related: RHEL-16182
---
src/shared/tpm2-util.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c
index 2c5d1741e7..4288d1b897 100644
--- a/src/shared/tpm2-util.c
+++ b/src/shared/tpm2-util.c
@@ -1519,7 +1519,8 @@ size_t tpm2_tpml_pcr_selection_weight(const TPML_PCR_SELECTION *l) {
bool tpm2_pcr_value_valid(const Tpm2PCRValue *pcr_value) {
int r;
- assert(pcr_value);
+ if (!pcr_value)
+ return false;
if (!TPM2_PCR_INDEX_VALID(pcr_value->index)) {
log_debug("PCR index %u invalid.", pcr_value->index);
@@ -1546,9 +1547,12 @@ bool tpm2_pcr_value_valid(const Tpm2PCRValue *pcr_value) {
*
* 1) all entries must be sorted in ascending order (e.g. using tpm2_sort_pcr_values())
* 2) all entries must be unique, i.e. there cannot be 2 entries with the same hash and index
+ *
+ * Returns true if all entries are valid (or if no entries are provided), false otherwise.
*/
bool tpm2_pcr_values_valid(const Tpm2PCRValue *pcr_values, size_t n_pcr_values) {
- assert(pcr_values || n_pcr_values == 0);
+ if (!pcr_values && n_pcr_values > 0)
+ return false;
for (size_t i = 0; i < n_pcr_values; i++) {
const Tpm2PCRValue *v = &pcr_values[i];