From: Lennart Poettering Date: Mon, 26 Jun 2023 14:13:27 +0000 (+0200) Subject: env-util: modernize env_name_is_valid_n() a bit X-Git-Tag: v254-rc1~86^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b07147e9c9d1f6ce032526a81961d005165614a;p=thirdparty%2Fsystemd.git env-util: modernize env_name_is_valid_n() a bit If the size is specified as SIZE_MAX, then imply strlen(). --- diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 5a933d7f08f..128102c688a 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -26,20 +26,21 @@ "_" 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;