aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-09-16 19:58:12 +0000
committerChristopher Faylor <me@cgf.cx>2005-09-16 19:58:12 +0000
commite4d981b9578d322d529b65aea55964f2249b5953 (patch)
tree542b700d1f1b17b69e3eda4bb8ffcb0ac72eb788
parent541ea31352ecb1a189143bd7822672740292e34b (diff)
downloadnewlib-e4d981b9578d322d529b65aea55964f2249b5953.zip
newlib-e4d981b9578d322d529b65aea55964f2249b5953.tar.gz
newlib-e4d981b9578d322d529b65aea55964f2249b5953.tar.bz2
* environ.cc (build_env): Clear envblock and return NULL on attempt to use env
var > 32K. * spawn.cc (spawn_guts): Set E2BIG if build_env detects an error.
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/environ.cc7
-rw-r--r--winsup/cygwin/spawn.cc5
3 files changed, 17 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 761df45..617f84a 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,11 @@
2005-09-16 Christopher Faylor <cgf@timesys.com>
+ * environ.cc (build_env): Clear envblock and return NULL on attempt to
+ use env var > 32K.
+ * spawn.cc (spawn_guts): Set E2BIG if build_env detects an error.
+
+2005-09-16 Christopher Faylor <cgf@timesys.com>
+
* environ.cc (environ_init): Protect with a 'myfault' in case
GetEnvironmentStrings misbehaves.
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 45e1ca7..b73c710 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -1034,6 +1034,12 @@ build_env (const char * const *envp, char *&envblock, int &envc,
p = *srcp; /* Don't worry about it */
len = strlen (p);
+ if (len >= 32 * 1024 * 1024)
+ {
+ free (envblock);
+ envblock = NULL;
+ break;
+ }
new_tl += len + 1; /* Keep running total of block length so far */
/* See if we need to increase the size of the block. */
@@ -1066,7 +1072,6 @@ build_env (const char * const *envp, char *&envblock, int &envc,
of buffer */
}
-
debug_printf ("envp %p, envc %d", newenv, envc);
return newenv;
}
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index ffafa8f..149a259 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -624,6 +624,11 @@ spawn_guts (const char * prog_arg, const char *const *argv,
cygheap->user.deimpersonate ();
moreinfo->envp = build_env (envp, envblock, moreinfo->envc, real_path.iscygexec ());
+ if (!moreinfo->envp || !envblock)
+ {
+ set_errno (E2BIG);
+ goto out;
+ }
ciresrv.set (chtype, real_path.iscygexec ());
ciresrv.moreinfo = moreinfo;