logd: fix privilege dropping order
authorGiovanni Giacobbi <giovanni@giacobbi.net>
Tue, 27 Jul 2021 12:39:28 +0000 (14:39 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 3 Aug 2021 20:45:30 +0000 (21:45 +0100)
Fixes: 41664054b8b1 ("logd: fix ignored return values in set{gid,uid}")
Signed-off-by: Giovanni Giacobbi <giovanni@giacobbi.net>
log/logd.c

index 5d6c458342490515d32560263ebfd07202927bfb..594b1e0421f117e7f387dab6e6ad6e59845a7c6b 100644 (file)
@@ -260,13 +260,13 @@ main(int argc, char **argv)
        ubus_auto_connect(&conn);
        p = getpwnam("logd");
        if (p) {
-               if (setuid(p->pw_uid) < 0) {
-                       fprintf(stderr, "setuid() failed: %s\n", strerror(errno));
+               if (setgid(p->pw_gid) < 0) {
+                       fprintf(stderr, "setgid() failed: %s\n", strerror(errno));
                        exit(1);
                }
 
-               if (setgid(p->pw_gid) < 0) {
-                       fprintf(stderr, "setgid() failed: %s\n", strerror(errno));
+               if (setuid(p->pw_uid) < 0) {
+                       fprintf(stderr, "setuid() failed: %s\n", strerror(errno));
                        exit(1);
                }
        }