summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2003-09-19 09:29:59 +0000
committerColin Watson <cjwatson@debian.org>2003-09-19 09:29:59 +0000
commit9dcbace70ec41ea21cd291e70bf6fd1bbd255a9e (patch)
tree4f3eaf0a295bfcf24e4c45bfce929b870d393ebf /session.c
parent9784e8f89704e17080b2d42ceeeef54ae73d51dd (diff)
Merge even more buffer allocation fixes from upstream (CAN-2003-0682,
#211434).
Diffstat (limited to 'session.c')
-rw-r--r--session.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/session.c b/session.c
index c75fea966..ec4a23ac5 100644
--- a/session.c
+++ b/session.c
@@ -844,8 +844,9 @@ static void
844child_set_env(char ***envp, u_int *envsizep, const char *name, 844child_set_env(char ***envp, u_int *envsizep, const char *name,
845 const char *value) 845 const char *value)
846{ 846{
847 u_int i, namelen;
848 char **env; 847 char **env;
848 u_int envsize;
849 u_int i, namelen;
849 850
850 /* 851 /*
851 * Find the slot where the value should be stored. If the variable 852 * Find the slot where the value should be stored. If the variable
@@ -862,12 +863,13 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
862 xfree(env[i]); 863 xfree(env[i]);
863 } else { 864 } else {
864 /* New variable. Expand if necessary. */ 865 /* New variable. Expand if necessary. */
865 if (i >= (*envsizep) - 1) { 866 envsize = *envsizep;
866 if (*envsizep >= 1000) 867 if (i >= envsize - 1) {
867 fatal("child_set_env: too many env vars," 868 if (envsize >= 1000)
868 " skipping: %.100s", name); 869 fatal("child_set_env: too many env vars");
869 (*envsizep) += 50; 870 envsize += 50;
870 env = (*envp) = xrealloc(env, (*envsizep) * sizeof(char *)); 871 env = (*envp) = xrealloc(env, envsize * sizeof(char *));
872 *envsizep = envsize;
871 } 873 }
872 /* Need to set the NULL pointer at end of array beyond the new slot. */ 874 /* Need to set the NULL pointer at end of array beyond the new slot. */
873 env[i + 1] = NULL; 875 env[i + 1] = NULL;