]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_owner: use correct UID/GID boundaries
authorJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 16:34:58 +0000 (17:34 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 22:14:28 +0000 (23:14 +0100)
-1 is a reserved number (chown uses it to denote "do not change"),
so the maximum libxt_owner should permit is up to UINT32_MAX-1.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
extensions/libxt_owner.c

index 4cd173e316f2f9931b41d6a62f3dcbe3ecc53e57..c8677a8c2d064881e472bbe7ac84b4d3f6ae25f4 100644 (file)
@@ -110,7 +110,7 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags,
                param_act(P_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER);
                if ((pwd = getpwnam(optarg)) != NULL)
                        id = pwd->pw_uid;
-               else if (!strtonum(optarg, NULL, &id, 0, ~(uid_t)0))
+               else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
                        param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg);
                if (invert)
                        info->invert |= IPT_OWNER_UID;
@@ -123,7 +123,7 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags,
                param_act(P_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER);
                if ((grp = getgrnam(optarg)) != NULL)
                        id = grp->gr_gid;
-               else if (!strtonum(optarg, NULL, &id, 0, ~(gid_t)0))
+               else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
                        param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg);
                if (invert)
                        info->invert |= IPT_OWNER_GID;
@@ -190,7 +190,7 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags,
                          *flags & FLAG_UID_OWNER);
                if ((pwd = getpwnam(optarg)) != NULL)
                        id = pwd->pw_uid;
-               else if (!strtonum(optarg, NULL, &id, 0, ~(uid_t)0))
+               else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
                        param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg);
                if (invert)
                        info->invert |= IP6T_OWNER_UID;
@@ -204,7 +204,7 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags,
                          *flags & FLAG_GID_OWNER);
                if ((grp = getgrnam(optarg)) != NULL)
                        id = grp->gr_gid;
-               else if (!strtonum(optarg, NULL, &id, 0, ~(gid_t)0))
+               else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
                        param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg);
                if (invert)
                        info->invert |= IP6T_OWNER_GID;
@@ -245,12 +245,12 @@ static void owner_parse_range(const char *s, unsigned int *from,
 {
        char *end;
 
-       /* 4294967295 is reserved, so subtract one from ~0 */
-       if (!strtonum(s, &end, from, 0, (~(uid_t)0) - 1))
+       /* -1 is reversed, so the max is one less than that. */
+       if (!strtonum(s, &end, from, 0, UINT32_MAX - 1))
                param_act(P_BAD_VALUE, "owner", opt, s);
        *to = *from;
        if (*end == '-' || *end == ':')
-               if (!strtonum(end + 1, &end, to, 0, (~(uid_t)0) - 1))
+               if (!strtonum(end + 1, &end, to, 0, UINT32_MAX - 1))
                        param_act(P_BAD_VALUE, "owner", opt, s);
        if (*end != '\0')
                param_act(P_BAD_VALUE, "owner", opt, s);