skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 185b93046a8e940c052a8fa8a134501e6ff2f2c1
parent 00fd4513a6cd6195655aec7297c974acb835d4a3
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed, 20 Dec 2023 15:32:40 +0000

 More accurate max env size detection in env_mergen

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Msrc/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 @@ -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 ; }