diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-20 15:32:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-12-20 15:32:40 +0000 |
commit | 185b93046a8e940c052a8fa8a134501e6ff2f2c1 (patch) | |
tree | 89d2002727168c9d30c731c511fb600fa4d08087 | |
parent | 00fd4513a6cd6195655aec7297c974acb835d4a3 (diff) | |
download | skalibs-185b93046a8e940c052a8fa8a134501e6ff2f2c1.tar.gz skalibs-185b93046a8e940c052a8fa8a134501e6ff2f2c1.tar.xz skalibs-185b93046a8e940c052a8fa8a134501e6ff2f2c1.zip |
More accurate max env size detection in env_mergen
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/libenvexec/env_mergen.c | 9 |
1 files 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 ; } |