summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArnaud Patard <arnaud.patard@collabora.com>2024-07-08 15:39:14 +0200
committerLuca Boccassi <bluca@debian.org>2024-08-05 19:32:26 +0200
commite7a93e75219b22424bab95fe45982f5eef21d581 (patch)
treeb2cdab87603a50ddb2f362b2c64643e5ce68a868 /src
parentlogind: add PreparingForShutdownWithMetadata property (diff)
downloadsystemd-e7a93e75219b22424bab95fe45982f5eef21d581.tar.xz
systemd-e7a93e75219b22424bab95fe45982f5eef21d581.zip
src/pcrlock/pcrlock.c: Handle empty pcrlock.d directories
Running the following commands: # mkdir -p /var/lib/pcrlock.d/123-empty.pcrlock.d # /usr/lib/systemd/systemd-pcrlock predict --pcr=1+2+3+4+5+16 Will result in: ... Floating point exception Running the following commands: # mkdir -p /var/lib/pcrlock.d/123-empty.pcrlock.d # /usr/lib/systemd/systemd-pcrlock make-policy --pcr=1+2+3+4+5+16 Will result to this (partial) log: ... Predicted future PCRs in 133us. [] ... Written policy digest 0000000000000000000000000000000000000000000000000000000000000000 to NV index 0x1921da6 ... So, add missing checks to handle gracefully cases where there's no variant inside the component. Signed-off-by: Arnaud Patard <arnaud.patard@collabora.com>
Diffstat (limited to 'src')
-rw-r--r--src/pcrlock/pcrlock.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c
index 113736b327..8acddf8a06 100644
--- a/src/pcrlock/pcrlock.c
+++ b/src/pcrlock/pcrlock.c
@@ -1927,6 +1927,9 @@ static int event_log_map_components(EventLog *el) {
continue;
}
+ if (c->n_variants == 0)
+ log_notice("Component '%s' has no defined variants.", c->id);
+
FOREACH_ARRAY(ii, c->variants, c->n_variants) {
EventLogComponentVariant *i = *ii;
@@ -4053,6 +4056,15 @@ static int event_log_predict_pcrs(
component = ASSERT_PTR(el->components[component_index]);
+ if (component->n_variants == 0)
+ return event_log_predict_pcrs(
+ el,
+ context,
+ parent_result,
+ component_index + 1, /* Next component */
+ pcr,
+ path);
+
FOREACH_ARRAY(ii, component->variants, component->n_variants) {
_cleanup_free_ Tpm2PCRPredictionResult *result = NULL;
EventLogComponentVariant *variant = *ii;
@@ -4111,7 +4123,9 @@ static ssize_t event_log_calculate_component_combinations(EventLog *el) {
/* Overflow check */
if (c->n_variants > (size_t) (SSIZE_MAX/count))
return log_error_errno(SYNTHETIC_ERRNO(E2BIG), "Too many component combinations.");
-
+ /* If no variant, this will lead to count being 0 and sigfpe */
+ if (c->n_variants == 0)
+ continue;
count *= c->n_variants;
}