]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kbd-util: fix use of ERRNO_IS_RESOURCE()
authorDmitry V. Levin <ldv@strace.io>
Fri, 7 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Sun, 16 Jul 2023 10:53:30 +0000 (10:53 +0000)
Given that ERRNO_IS_RESOURCE() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_RESOURCE() is the value
returned by recurse_dir_at() which can legitimately return positive
values without errno semantics, so fix this by moving the ERRNO_IS_RESOURCE()
invocation to the branch where the return value is known to be negative.

src/shared/kbd-util.c

index 31008625483ecf935e997f30d7469d8cd4745fff..e6fe973471bb093a05acefa22e9d50bbf50be0c4 100644 (file)
@@ -145,11 +145,11 @@ int keymap_exists(const char *name) {
                                 &(struct recurse_dir_userdata) {
                                         .keymap_name = name,
                                 });
-                if (r == -ENOENT)
-                        continue;
-                if (ERRNO_IS_RESOURCE(r))
-                        return r;
                 if (r < 0) {
+                        if (r == -ENOENT)
+                                continue;
+                        if (ERRNO_IS_RESOURCE(r))
+                                return r;
                         log_debug_errno(r, "Failed to read keymap list from %s, ignoring: %m", dir);
                         continue;
                 }