systemd/backport-verify-fix-segmentation-fault.patch
2023-12-06 16:52:45 +08:00

61 lines
2.2 KiB
Diff

From fc9de36a3b60c69a17442aabf215e2d87e697e6f Mon Sep 17 00:00:00 2001
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
Date: Wed, 13 Nov 2019 06:30:58 -0500
Subject: [PATCH 0593/1760] verify: fix segmentation fault
systemd-analyze verify command now results in segmentation fault if two
consecutive non-existent unit file names are given:
# ./build/systemd-analyze a.service b.service
...<snip irrelevant part>...
Unit a.service not found.
Unit b.service not found.
Segmentation fault (core dumped)
The cause of this is a wrong handling of return value of
manager_load_startable_unit_or_warn() in verify_units() in failure case.
It looks that the current logic wants to assign the first error status
throughout verify_units() into variable r and count up variable count only when
a given unit file exists.
However, due to the wrong handling of the return value of
manager_load_startable_unit_or_warn() in verify_units(), the variable count is
unexpectedly incremented even when there is no such unit file because the
variable r already contains non-zero value in the 2nd failure, set by the 1st
failure, and then the condition k < 0 && r == 0 evaluates to false.
This commit fixes the wrong handling of return value of
manager_load_startable_unit_or_warn() in verify_units().
Reference: https://github.com/systemd/systemd/commit/fc9de36a3b60c69a17442aabf215e2d87e697e6f
Conflict: NA
---
src/analyze/analyze-verify.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c
index 16b07cc..4cfbdfa 100644
--- a/src/analyze/analyze-verify.c
+++ b/src/analyze/analyze-verify.c
@@ -271,10 +271,13 @@ int verify_units(char **filenames, UnitFileScope scope, bool check_man, bool run
}
k = manager_load_startable_unit_or_warn(m, NULL, prepared, &units[count]);
- if (k < 0 && r == 0)
- r = k;
- else
- count++;
+ if (k < 0) {
+ if (r == 0)
+ r = k;
+ continue;
+ }
+
+ count++;
}
for (i = 0; i < count; i++) {
--
1.8.3.1