libbb: make parse_chown_usergroup_or_die() set unspecified uid/gid to -1
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 19 Oct 2015 02:37:19 +0000 (04:37 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 19 Oct 2015 02:37:19 +0000 (04:37 +0200)
function                                             old     new   delta
parse_chown_usergroup_or_die                         102     115     +13
chown_main                                           190     175     -15
start_stop_daemon_main                              1043    1027     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-31)            Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/chown.c
debianutils/start_stop_daemon.c
libpwdgrp/uidgid_get.c

index eaa1ee2a391ca8b2a14174aab4075110e4469524..247aa3bf12db31dfa54e33e860e24f6f62cbb726 100644 (file)
@@ -112,10 +112,6 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
        int opt, flags;
        struct param_t param;
 
-       /* Just -1 might not work: uid_t may be unsigned long */
-       param.ugid.uid = -1L;
-       param.ugid.gid = -1L;
-
 #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
        applet_long_options = chown_longopts;
 #endif
index 42f1943dd079be373860ab26a82bddd4e2e63bfe..d7c730f453500b7948333d26811c84a5633503ee 100644 (file)
@@ -539,15 +539,15 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
                write_pidfile(pidfile);
        }
        if (opt & OPT_c) {
-               struct bb_uidgid_t ugid = { -1, -1 };
+               struct bb_uidgid_t ugid;
                parse_chown_usergroup_or_die(&ugid, chuid);
-               if (ugid.uid != (uid_t) -1) {
+               if (ugid.uid != (uid_t) -1L) {
                        struct passwd *pw = xgetpwuid(ugid.uid);
-                       if (ugid.gid != (gid_t) -1)
+                       if (ugid.gid != (gid_t) -1L)
                                pw->pw_gid = ugid.gid;
                        /* initgroups, setgid, setuid: */
                        change_identity(pw);
-               } else if (ugid.gid != (gid_t) -1) {
+               } else if (ugid.gid != (gid_t) -1L) {
                        xsetgid(ugid.gid);
                        setgroups(1, &ugid.gid);
                }
index eeb65191fc4f775a947fdc6ef43c80be7de369cd..1199f23f960cb11a687252d28d9616e436b46051 100644 (file)
@@ -90,6 +90,8 @@ void FAST_FUNC parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_gr
 {
        char *group;
 
+       u->uid = u->gid = (gid_t)-1L;
+
        /* Check if there is a group name */
        group = strchr(user_group, '.'); /* deprecated? */
        if (!group)