summaryrefslogtreecommitdiff
path: root/src/libenvexec/env_mergen.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-12-20 15:32:40 +0000
committerLaurent Bercot <ska@appnovation.com>2023-12-20 15:32:40 +0000
commit185b93046a8e940c052a8fa8a134501e6ff2f2c1 (patch)
tree89d2002727168c9d30c731c511fb600fa4d08087 /src/libenvexec/env_mergen.c
parent00fd4513a6cd6195655aec7297c974acb835d4a3 (diff)
downloadskalibs-185b93046a8e940c052a8fa8a134501e6ff2f2c1.tar.xz
More accurate max env size detection in env_mergen
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libenvexec/env_mergen.c')
-rw-r--r--src/libenvexec/env_mergen.c9
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 ;
}