]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdb: cleanup use of ERRNO_IS_PRIVILEGE()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_PRIVILEGE() 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_PRIVILEGE() is the value
returned by json_parse_file() which is not expected to return any positive
values, but let's be consistent anyway and move the ERRNO_IS_PRIVILEGE()
invocation to the branch where the return value is known to be negative.

src/shared/userdb-dropin.c

index 5d79f4688a00c11e35f727b4c32dbb3776f8bda2..309f33b5b5bb085521f5a75c547afe533b1828a1 100644 (file)
@@ -57,13 +57,14 @@ static int load_user(
                 }
 
                 r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL);
-                if (ERRNO_IS_PRIVILEGE(r))
-                        have_privileged = false;
-                else if (r == -ENOENT)
-                        have_privileged = true; /* if the privileged file doesn't exist, we are complete */
-                else if (r < 0)
-                        return r;
-                else {
+                if (r < 0) {
+                        if (ERRNO_IS_PRIVILEGE(r))
+                                have_privileged = false;
+                        else if (r == -ENOENT)
+                                have_privileged = true; /* if the privileged file doesn't exist, we are complete */
+                        else
+                                return r;
+                } else {
                         r = json_variant_merge(&v, privileged_v);
                         if (r < 0)
                                 return r;
@@ -201,13 +202,14 @@ static int load_group(
                 }
 
                 r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL);
-                if (ERRNO_IS_PRIVILEGE(r))
-                        have_privileged = false;
-                else if (r == -ENOENT)
-                        have_privileged = true; /* if the privileged file doesn't exist, we are complete */
-                else if (r < 0)
-                        return r;
-                else {
+                if (r < 0) {
+                        if (ERRNO_IS_PRIVILEGE(r))
+                                have_privileged = false;
+                        else if (r == -ENOENT)
+                                have_privileged = true; /* if the privileged file doesn't exist, we are complete */
+                        else
+                                return r;
+                } else {
                         r = json_variant_merge(&v, privileged_v);
                         if (r < 0)
                                 return r;