1
0
mirror of https://github.com/systemd/systemd synced 2026-04-11 17:44:58 +02:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
a420d71793 NEWS: finalize release 2021-12-23 21:09:35 +01:00
Yu Watanabe
558ad6bd38
analyze: fix segfault when malloc() fails (#21874)
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.
2021-12-23 21:03:16 +01:00
Zbigniew Jędrzejewski-Szmek
10c8c32f13
Merge pull request #21869 from yuwata/sd-journal-fix-segfault
sd-journal: fix segfault
2021-12-23 20:07:41 +01:00
Yu Watanabe
39dfc0de05 sd-journal: fix segfault when match_new() fails
Fixes #21867.
2021-12-23 21:45:32 +09:00
Yu Watanabe
418cce628c sd-journal: free incomplete match on failure 2021-12-23 21:35:29 +09:00
3 changed files with 14 additions and 10 deletions

2
NEWS
View File

@ -1,6 +1,6 @@
systemd System and Service Manager systemd System and Service Manager
CHANGES WITH 250 in spe: CHANGES WITH 250:
* Support for encrypted and authenticated credentials has been added. * Support for encrypted and authenticated credentials has been added.
This extends the credential logic introduced with v247 to support This extends the credential logic introduced with v247 to support

View File

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

View File

@ -212,7 +212,7 @@ static Match *match_new(Match *p, MatchType t) {
return m; return m;
} }
static void match_free(Match *m) { static Match *match_free(Match *m) {
assert(m); assert(m);
while (m->matches) while (m->matches)
@ -222,18 +222,18 @@ static void match_free(Match *m) {
LIST_REMOVE(matches, m->parent->matches, m); LIST_REMOVE(matches, m->parent->matches, m);
free(m->data); free(m->data);
free(m); return mfree(m);
} }
static void match_free_if_empty(Match *m) { static Match *match_free_if_empty(Match *m) {
if (!m || m->matches) if (!m || m->matches)
return; return m;
match_free(m); return match_free(m);
} }
_public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) { _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
Match *l3, *l4, *add_here = NULL, *m; Match *l3, *l4, *add_here = NULL, *m = NULL;
uint64_t hash; uint64_t hash;
assert_return(j, -EINVAL); assert_return(j, -EINVAL);
@ -322,10 +322,11 @@ _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size)
return 0; return 0;
fail: fail:
match_free(m);
match_free_if_empty(add_here); match_free_if_empty(add_here);
match_free_if_empty(j->level2); j->level2 = match_free_if_empty(j->level2);
match_free_if_empty(j->level1); j->level1 = match_free_if_empty(j->level1);
match_free_if_empty(j->level0); j->level0 = match_free_if_empty(j->level0);
return -ENOMEM; return -ENOMEM;
} }