]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dbus: limit the number of env variables to something reasonable, vol. 3
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 6 May 2026 12:03:29 +0000 (14:03 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 May 2026 15:34:32 +0000 (16:34 +0100)
Let's limit the number of environment variables when creating a
transient unit via StartTransientUnit as well, since validating the
environment variable names/assignments is expensive.

Follow-up for 49c1e1bcf2b482b6de35a4212a06ed1d8c382745.

src/core/dbus-execute.c

index aea9fbb304e22e1c8460df0a93d49895400233b8..2329762f16b68c8d02e81c2992e6a958ce1cf87d 100644 (file)
@@ -3456,6 +3456,9 @@ int bus_exec_context_set_transient_property(
                 if (r < 0)
                         return r;
 
+                if (strv_length(l) > ENVIRONMENT_ASSIGNMENTS_MAX)
+                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
+                                                "Too many environment assignments.");
                 if (!strv_env_is_valid(l))
                         return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
 
@@ -3490,6 +3493,9 @@ int bus_exec_context_set_transient_property(
                 if (r < 0)
                         return r;
 
+                if (strv_length(l) > ENVIRONMENT_ASSIGNMENTS_MAX)
+                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
+                                                "Too many environment variable names or assignments.");
                 if (!strv_env_name_or_assignment_is_valid(l))
                         return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
 
@@ -3642,6 +3648,9 @@ int bus_exec_context_set_transient_property(
                 if (r < 0)
                         return r;
 
+                if (strv_length(l) > ENVIRONMENT_ASSIGNMENTS_MAX)
+                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
+                                                "Too many environment variable names.");
                 if (!strv_env_name_is_valid(l))
                         return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");