]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: tighten two filename length checks
authorLennart Poettering <lennart@poettering.net>
Mon, 8 Mar 2021 20:44:39 +0000 (21:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 8 Mar 2021 21:47:14 +0000 (22:47 +0100)
This fixes two checks where we compare string sizes when validating with
FILENAME_MAX. In both cases the check apparently wants to check if the
name fits in a filename, but that's not actually what FILENAME_MAX can
be used for, as it — in contrast to what the name suggests — actually
encodes the maximum length of a path.

In both cases the stricter change doesn't actually change much, but the
use of FILENAME_MAX is still misleading and typically wrong.

src/basic/cgroup-util.c
src/basic/user-util.c

index 0ecb8d944e98ea133dd25cb47cce5a17ab6efda0..7372b06024ad45b947f4e98c842ffaf23d877a7f 100644 (file)
@@ -1567,7 +1567,7 @@ bool cg_controller_is_valid(const char *p) {
                 if (!strchr(CONTROLLER_VALID, *t))
                         return false;
 
-        if (t - p > FILENAME_MAX)
+        if (t - p > NAME_MAX)
                 return false;
 
         return true;
index 1fad342cef3c7f9f4485bc38d970edb3e36f8e8c..0ea4e409fac5991e8b5f37ced3e04fde43a66808 100644 (file)
@@ -836,7 +836,7 @@ bool valid_user_group_name(const char *u, ValidUserFlags flags) {
 
                 if (l > (size_t) sz)
                         return false;
-                if (l > FILENAME_MAX)
+                if (l > NAME_MAX) /* must fit in a filename */
                         return false;
                 if (l > UT_NAMESIZE - 1)
                         return false;