Cygwin: build_env: fix off-by-one bug when re-adding PATH

Adding default winvar 'PATH=C:\cygwin64\binZ' to an environment that is
already allocated for 'SYSTEMROOT=ZWINDIR=Z', we need to count that
trailing (Z)ero as well.  Otherwise we trigger this assertion failure:

$ /bin/env -i SYSTEMROOT= WINDIR= /bin/env
assertion "(s - envblock) <= tl" failed: file "/home/corinna/src/cygwin/cygwin-3.0.7/cygwin-3.0.7-1.x86_64/src/newlib-cygwin/winsup/cygwin/environ.cc", line 1302, function: char** build_env(const char* const*, WCHAR*&, int&, bool, HANDLE)
Aborted (core dumped)
This commit is contained in:
Michael Haubenwallner 2019-08-07 10:51:16 +02:00 committed by Corinna Vinschen
parent 98669a2476
commit 472fbb8b97

View File

@ -1295,7 +1295,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
during execve. */
if (!saw_PATH)
{
new_tl += cygheap->installation_dir.Length / sizeof (WCHAR) + 5;
new_tl += cygheap->installation_dir.Length / sizeof (WCHAR) + 5 + 1;
if (new_tl > tl)
tl = raise_envblock (new_tl, envblock, s);
s = wcpcpy (wcpcpy (s, L"PATH="),