From 9a24f5edcc1c16f2afaa943dfd39f413322a5a0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 24 May 2021 22:49:56 +0200 Subject: [PATCH] systemctl: avoid crash when pattern expands to empty unit list Fixes #19652. (cherry picked from commit ffcd68385226d4b499dbff0123271e1d3fb8f516) --- src/systemctl/systemctl-edit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index 6e7c67ef2f..87650850fe 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -526,6 +526,8 @@ int edit(int argc, char *argv[], void *userdata) { r = expand_unit_names(bus, strv_skip(argv, 1), NULL, &names, NULL); if (r < 0) return log_error_errno(r, "Failed to expand names: %m"); + if (strv_isempty(names)) + return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "No units matched the specified patterns."); STRV_FOREACH(tmp, names) { r = unit_is_masked(bus, &lp, *tmp); -- 2.25.1