]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
env-util: add explicit size check before strndupa() in strv_env_get_n()
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2023 14:14:27 +0000 (16:14 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Jun 2023 11:49:46 +0000 (13:49 +0200)
Let's better be safe than sorry.

src/basic/env-util.c

index 128102c688a7cb51a14bad7944bd1fdafd87e1bf..8cc7b72511e7c60b2151729bb48847c49344128d 100644 (file)
@@ -514,6 +514,10 @@ char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) {
         if (flags & REPLACE_ENV_USE_ENVIRONMENT) {
                 const char *t;
 
+                /* Safety check that the name is not overly long, before we do a stack allocation */
+                if (k > (size_t) sysconf(_SC_ARG_MAX) - 2)
+                        return NULL;
+
                 t = strndupa_safe(name, k);
                 return getenv(t);
         };