diff options
author | nectar <nectar@FreeBSD.org> | 2003-09-17 14:36:14 +0000 |
---|---|---|
committer | nectar <nectar@FreeBSD.org> | 2003-09-17 14:36:14 +0000 |
commit | bacf67e6ca3931195d8874d7bf269cbea204a325 (patch) | |
tree | c525a53d68d3652b2c3f23b11d6a4b2644005e41 /crypto/openssh/session.c | |
parent | 0c91aa7050a5a698cd77122c7a51de20355ce314 (diff) | |
download | FreeBSD-src-bacf67e6ca3931195d8874d7bf269cbea204a325.zip FreeBSD-src-bacf67e6ca3931195d8874d7bf269cbea204a325.tar.gz |
Correct more cases of allocation size bookkeeping being updated before
calling functions which can potentially fail and cause cleanups to be
invoked.
Submitted by: Solar Designer <solar@openwall.com>
Diffstat (limited to 'crypto/openssh/session.c')
-rw-r--r-- | crypto/openssh/session.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crypto/openssh/session.c b/crypto/openssh/session.c index 06ddb4c..f2d73a4 100644 --- a/crypto/openssh/session.c +++ b/crypto/openssh/session.c @@ -863,8 +863,9 @@ static void child_set_env(char ***envp, u_int *envsizep, const char *name, const char *value) { - u_int i, namelen; char **env; + u_int envsize; + u_int i, namelen; /* * Find the slot where the value should be stored. If the variable @@ -881,12 +882,13 @@ child_set_env(char ***envp, u_int *envsizep, const char *name, xfree(env[i]); } else { /* New variable. Expand if necessary. */ - if (i >= (*envsizep) - 1) { - if (*envsizep >= 1000) - fatal("child_set_env: too many env vars," - " skipping: %.100s", name); - (*envsizep) += 50; - env = (*envp) = xrealloc(env, (*envsizep) * sizeof(char *)); + envsize = *envsizep; + if (i >= envsize - 1) { + if (envsize >= 1000) + fatal("child_set_env: too many env vars"); + envsize += 50; + env = (*envp) = xrealloc(env, envsize * sizeof(char *)); + *envsizep = envsize; } /* Need to set the NULL pointer at end of array beyond the new slot. */ env[i + 1] = NULL; |