Commit cdfabb5e authored by Martin Pitt's avatar Martin Pitt

Fix segfault with units that depend on themselves

Patch cherry-picked from upstream.

Closes: #780675
parent bb539765
...@@ -7,6 +7,7 @@ systemd (215-13) UNRELEASED; urgency=medium ...@@ -7,6 +7,7 @@ systemd (215-13) UNRELEASED; urgency=medium
* Check for correct architecture identifiers for SuperH. (Closes: #779710) * Check for correct architecture identifiers for SuperH. (Closes: #779710)
* networkd: Fix stopping v4 dhcpclient when the carrier is lost. Thanks * networkd: Fix stopping v4 dhcpclient when the carrier is lost. Thanks
Christos Trochalakis! (Closes: #779571) Christos Trochalakis! (Closes: #779571)
* Fix segfault with units that depend on themselves. (Closes: #780675)
-- Martin Pitt <mpitt@debian.org> Mon, 16 Feb 2015 16:11:12 +0100 -- Martin Pitt <mpitt@debian.org> Mon, 16 Feb 2015 16:11:12 +0100
......
From: =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Thu, 7 Aug 2014 20:42:58 -0400
Subject: core: do not add dependencies to self
Adds a pair of files which cause a segfault (also with
systemd-analyze verify).
https://bugzilla.redhat.com/show_bug.cgi?id=1124843
---
src/core/load-dropin.c | 2 +-
src/core/unit.c | 16 ++++++++++++----
test/loopy.service | 2 ++
test/loopy.service.d/compat.conf | 5 +++++
test/loopy2.service | 1 +
5 files changed, 21 insertions(+), 5 deletions(-)
create mode 100644 test/loopy.service
create mode 100644 test/loopy.service.d/compat.conf
create mode 120000 test/loopy2.service
diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index 6ff592b..b2fdf3a 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -181,7 +181,7 @@ int unit_load_dropin(Unit *u) {
}
u->dropin_paths = unit_find_dropin_paths(u);
- if (! u->dropin_paths)
+ if (!u->dropin_paths)
return 0;
STRV_FOREACH(f, u->dropin_paths) {
diff --git a/src/core/unit.c b/src/core/unit.c
index 0e4ebfd..7dbbf73 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -597,14 +597,22 @@ static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
UnitDependency k;
for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++) {
- r = set_remove_and_put(back->dependencies[k], other, u);
- if (r == -EEXIST)
+ /* Do not add dependencies between u and itself */
+ if (back == u) {
set_remove(back->dependencies[k], other);
- else
- assert(r >= 0 || r == -ENOENT);
+ } else {
+ r = set_remove_and_put(back->dependencies[k], other, u);
+ if (r == -EEXIST)
+ set_remove(back->dependencies[k], other);
+ else
+ assert(r >= 0 || r == -ENOENT);
+ }
}
}
+ /* Also do not move dependencies on u to itself */
+ set_remove(other->dependencies[d], u);
+
complete_move(&u->dependencies[d], &other->dependencies[d]);
set_free(other->dependencies[d]);
diff --git a/test/loopy.service b/test/loopy.service
new file mode 100644
index 0000000..9eb6457
--- /dev/null
+++ b/test/loopy.service
@@ -0,0 +1,2 @@
+[Service]
+ExecStart=/bin/true
diff --git a/test/loopy.service.d/compat.conf b/test/loopy.service.d/compat.conf
new file mode 100644
index 0000000..51b84b8
--- /dev/null
+++ b/test/loopy.service.d/compat.conf
@@ -0,0 +1,5 @@
+[Unit]
+BindsTo=loopy2.service
+
+[Install]
+Also=loopy2.service
diff --git a/test/loopy2.service b/test/loopy2.service
new file mode 120000
index 0000000..961b1fe
--- /dev/null
+++ b/test/loopy2.service
@@ -0,0 +1 @@
+loopy.service
\ No newline at end of file
...@@ -137,6 +137,7 @@ rules-Fix-by-path-of-mmc-RPMB-partitions-and-don-t-b.patch ...@@ -137,6 +137,7 @@ rules-Fix-by-path-of-mmc-RPMB-partitions-and-don-t-b.patch
man-document-failed.patch man-document-failed.patch
Use-correct-uname-identifiers-in-arch_map-for-SuperH.patch Use-correct-uname-identifiers-in-arch_map-for-SuperH.patch
networkd-link-fix-stopping-v4-dhcpclient-when-the-ca.patch networkd-link-fix-stopping-v4-dhcpclient-when-the-ca.patch
core-do-not-add-dependencies-to-self.patch
## Debian specific patches: ## Debian specific patches:
Add-back-support-for-Debian-specific-config-files.patch Add-back-support-for-Debian-specific-config-files.patch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment