From 185b93046a8e940c052a8fa8a134501e6ff2f2c1 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 20 Dec 2023 15:32:40 +0000 Subject: More accurate max env size detection in env_mergen Signed-off-by: Laurent Bercot --- src/libenvexec/env_mergen.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libenvexec/env_mergen.c b/src/libenvexec/env_mergen.c index acc7c39..64a77cb 100644 --- a/src/libenvexec/env_mergen.c +++ b/src/libenvexec/env_mergen.c @@ -10,7 +10,7 @@ size_t env_mergen (char const **v, size_t vmax, char const *const *envp, size_t { size_t vlen = envlen ; size_t i = 0 ; - if (envlen + n + 1 > vmax) return (errno = ENAMETOOLONG, 0) ; + if (envlen >= vmax) return 0 ; for (; i < envlen ; i++) v[i] = envp[i] ; for (i = 0 ; i < modiflen ; i += strlen(modifs + i) + 1) { @@ -19,8 +19,13 @@ size_t env_mergen (char const **v, size_t vmax, char const *const *envp, size_t for (; j < vlen ; j++) if (!strncmp(modifs + i, v[j], split) && (v[j][split] == '=')) break ; if (j < vlen) v[j] = v[--vlen] ; - if (modifs[i + split]) v[vlen++] = modifs + i ; + if (modifs[i + split]) + { + if (vlen >= vmax) return 0 ; + v[vlen++] = modifs + i ; + } } + if (vlen >= vmax) return 0 ; v[vlen++] = 0 ; return vlen ; } -- cgit v1.2.3