]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
child_set_eng: verify both env pointer and count.
authorDarren Tucker <dtucker@dtucker.net>
Thu, 30 Mar 2023 02:53:29 +0000 (13:53 +1100)
committerDarren Tucker <dtucker@dtucker.net>
Thu, 30 Mar 2023 03:08:35 +0000 (14:08 +1100)
If child_set env was called with a NULL env pointer and a non-zero count
it would end up in a null deref, although we don't currently do this.
Prompted by Coverity CID 291850, tweak & ok djm@

misc.c

diff --git a/misc.c b/misc.c
index 6135b15567a4f6fe2dc113e6b380825bd536d1b5..63c3d4d29de915c6edaefe4e5b0fe24649fb3831 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -2273,6 +2273,8 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
         * If we're passed an uninitialized list, allocate a single null
         * entry before continuing.
         */
+       if ((*envp == NULL) != (*envsizep == 0))
+               fatal_f("environment size mismatch");
        if (*envp == NULL && *envsizep == 0) {
                *envp = xmalloc(sizeof(char *));
                *envp[0] = NULL;