LoadCredentials: do not assert on invalid syntax
authorLuca Boccassi <luca.boccassi@microsoft.com>
Thu, 1 Apr 2021 21:18:29 +0000 (22:18 +0100)
committerLuca Boccassi <bluca@debian.org>
Sun, 18 Jun 2023 14:55:54 +0000 (15:55 +0100)
LoadCredentials=foo causes an assertion to be triggered, as we
are not checking that the rvalue's right hand side part is non-empty
before using it in unit_full_printf.

Fixes #19178

# printf [Service]nLoadCredential=passwd.hashed-password.rootn > hello.service
# systemd-analyze verify ./hello.service
...
Assertion 'format' failed at src/core/unit-printf.c:232, function unit_full_printf(). Aborting.
Aborted (core dumped)

(cherry picked from commit f7a6f1226e800f7695c2073675523062ea697aa4)

Gbp-Pq: Name LoadCredentials-do-not-assert-on-invalid-syntax.patch

src/core/load-fragment.c

index 4964249bf213e2cdf00bfa288d6ef17359609dcb..5b66fb1628c4659406d1633dd11f4d73af57c949 100644 (file)
@@ -4569,7 +4569,7 @@ int config_parse_load_credential(
         r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
         if (r == -ENOMEM)
                 return log_oom();
-        if (r <= 0) {
+        if (r <= 0 || isempty(p)) {
                 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
                 return 0;
         }