]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: Fix {g,u}id_type on Big Endian
authorPhil Sutter <phil@nwl.cc>
Tue, 9 Mar 2021 20:24:30 +0000 (21:24 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 30 Nov 2021 13:57:46 +0000 (14:57 +0100)
Using a 64bit variable to temporarily hold the parsed value works only
on Little Endian. uid_t and gid_t (and therefore also pw->pw_uid and
gr->gr_gid) are 32bit.
To fix this, use uid_t/gid_t for the temporary variable but keep the
64bit one for numeric parsing so values exceeding 32bits are still
detected.

Fixes: e0ed4c45d9ad2 ("meta: relax restriction on UID/GID parsing")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/meta.c

index bdd10269569d23980e012955c675865110c4c0eb..1794495ebba1c048836ce8457d41a13452c1df23 100644 (file)
@@ -220,18 +220,20 @@ static struct error_record *uid_type_parse(struct parse_ctx *ctx,
                                           struct expr **res)
 {
        struct passwd *pw;
-       uint64_t uid;
+       uid_t uid;
        char *endptr = NULL;
 
        pw = getpwnam(sym->identifier);
        if (pw != NULL)
                uid = pw->pw_uid;
        else {
-               uid = strtoull(sym->identifier, &endptr, 10);
-               if (uid > UINT32_MAX)
+               uint64_t _uid = strtoull(sym->identifier, &endptr, 10);
+
+               if (_uid > UINT32_MAX)
                        return error(&sym->location, "Value too large");
                else if (*endptr)
                        return error(&sym->location, "User does not exist");
+               uid = _uid;
        }
 
        *res = constant_expr_alloc(&sym->location, sym->dtype,
@@ -274,18 +276,20 @@ static struct error_record *gid_type_parse(struct parse_ctx *ctx,
                                           struct expr **res)
 {
        struct group *gr;
-       uint64_t gid;
+       gid_t gid;
        char *endptr = NULL;
 
        gr = getgrnam(sym->identifier);
        if (gr != NULL)
                gid = gr->gr_gid;
        else {
-               gid = strtoull(sym->identifier, &endptr, 0);
-               if (gid > UINT32_MAX)
+               uint64_t _gid = strtoull(sym->identifier, &endptr, 0);
+
+               if (_gid > UINT32_MAX)
                        return error(&sym->location, "Value too large");
                else if (*endptr)
                        return error(&sym->location, "Group does not exist");
+               gid = _gid;
        }
 
        *res = constant_expr_alloc(&sym->location, sym->dtype,