]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
env-util: modernize env_name_is_valid_n() a bit
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2023 14:13:27 +0000 (16:13 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Jun 2023 11:49:46 +0000 (13:49 +0200)
If the size is specified as SIZE_MAX, then imply strlen().

src/basic/env-util.c

index 5a933d7f08faec8a768eb58f3c5408581b3532c7..128102c688a7cb51a14bad7944bd1fdafd87e1bf 100644 (file)
         "_"
 
 static bool env_name_is_valid_n(const char *e, size_t n) {
-        if (!e)
-                return false;
+
+        if (n == SIZE_MAX)
+                n = strlen_ptr(e);
 
         if (n <= 0)
                 return false;
 
+        assert(e);
+
         if (ascii_isdigit(e[0]))
                 return false;
 
-        /* POSIX says the overall size of the environment block cannot
-         * be > ARG_MAX, an individual assignment hence cannot be
-         * either. Discounting the equal sign and trailing NUL this
-         * hence leaves ARG_MAX-2 as longest possible variable
-         * name. */
+        /* POSIX says the overall size of the environment block cannot be > ARG_MAX, an individual assignment
+         * hence cannot be either. Discounting the equal sign and trailing NUL this hence leaves ARG_MAX-2 as
+         * longest possible variable name. */
         if (n > (size_t) sysconf(_SC_ARG_MAX) - 2)
                 return false;