]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: fix segfault when malloc() fails (#21874)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Dec 2021 20:03:16 +0000 (05:03 +0900)
committerGitHub <noreply@github.com>
Thu, 23 Dec 2021 20:03:16 +0000 (21:03 +0100)
Fixes #21872.

log_syntax_callback sets 's', a.k.a. '*userdata', to POINTER_MAX to signal allocation failure.
If the error does not cause immediate failure of the program, and log_syntax_callback is called
again, it would try to use 's' as a pointer to a set and fail badly.

src/analyze/analyze-verify.c

index f3e5d3530d6587b9479ed7a57ef464e761346a28..943a1f27de9cd1798e7555f1fa4eb2951012b1bd 100644 (file)
@@ -26,6 +26,9 @@ static void log_syntax_callback(const char *unit, int level, void *userdata) {
         if (level > LOG_WARNING)
                 return;
 
+        if (*s == POINTER_MAX)
+                return;
+
         r = set_put_strdup(s, unit);
         if (r < 0) {
                 set_free_free(*s);