From: Mike Yuan Date: Wed, 28 May 2025 18:47:50 +0000 (+0200) Subject: env-util: add missing assertions X-Git-Tag: v258-rc1~443^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d67fcabedc9eac4e19fff810cd10564dda3305f;p=thirdparty%2Fsystemd.git env-util: add missing assertions --- diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 8a841f057a4..7bdfdec8517 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -375,6 +375,7 @@ int strv_env_replace_consume(char ***l, char *p) { const char *t, *name; int r; + assert(l); assert(p); /* Replace first occurrence of the env var or add a new one in the string list. Drop other @@ -408,6 +409,9 @@ int strv_env_replace_consume(char ***l, char *p) { int strv_env_replace_strdup(char ***l, const char *assignment) { /* Like strv_env_replace_consume(), but copies the argument. */ + assert(l); + assert(assignment); + char *p = strdup(assignment); if (!p) return -ENOMEM; @@ -416,11 +420,14 @@ int strv_env_replace_strdup(char ***l, const char *assignment) { } int strv_env_replace_strdup_passthrough(char ***l, const char *assignment) { - /* Like strv_env_replace_strdup(), but pulls the variable from the environment of - * the calling program, if a variable name without value is specified. - */ char *p; + /* Like strv_env_replace_strdup(), but pulls the variable from the environment of + * the calling program, if a variable name without value is specified. */ + + assert(l); + assert(assignment); + if (strchr(assignment, '=')) { if (!env_assignment_is_valid(assignment)) return -EINVAL; @@ -442,6 +449,8 @@ int strv_env_replace_strdup_passthrough(char ***l, const char *assignment) { } int strv_env_assign(char ***l, const char *key, const char *value) { + assert(l); + if (!env_name_is_valid(key)) return -EINVAL;