From 40c5d5d2a10de273f0b37fc9e76a0138f190685e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 23 Feb 2023 11:03:17 +0900 Subject: [PATCH 1/2] sd-event: fix use of uninitialized variable Follow-up for 158fe190afe37b222c9dc2c53bd7be426b92ef89. Fixes CID#1505670. --- src/libsystemd/sd-event/sd-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 5303a14cd69..403127d6694 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -1917,7 +1917,7 @@ _public_ int sd_event_add_memory_pressure( _cleanup_(source_freep) sd_event_source *s = NULL; _cleanup_close_ int path_fd = -1, fd = -1; _cleanup_free_ void *write_buffer = NULL; - const char *watch, *watch_fallback, *env; + const char *watch, *watch_fallback = NULL, *env; size_t write_buffer_size = 0; struct stat st; uint32_t events; From 63b1e67ed94fd033427ab09d7d20f879d6939e6f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 23 Feb 2023 11:04:44 +0900 Subject: [PATCH 2/2] sd-event: fix error handling Follow-up for 158fe190afe37b222c9dc2c53bd7be426b92ef89. --- src/libsystemd/sd-event/sd-event.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 403127d6694..3db9122fc2e 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -2028,10 +2028,11 @@ _public_ int sd_event_add_memory_pressure( return locked ? -ENOENT : -EOPNOTSUPP; path_fd = open(watch_fallback, O_PATH|O_CLOEXEC); - if (errno == ENOENT) /* PSI is not available in the kernel even under the fallback path? */ - return -EOPNOTSUPP; - if (errno < 0) + if (path_fd < 0) { + if (errno == ENOENT) /* PSI is not available in the kernel even under the fallback path? */ + return -EOPNOTSUPP; return -errno; + } } if (fstat(path_fd, &st) < 0)