summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorarton <arton@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-19 09:28:49 +0000
committerarton <arton@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-19 09:28:49 +0000
commit5281610f919f96fd0ec1a14a53ad42b54bc8d373 (patch)
tree4bd6221f808183d188c26a952c81f25c92223a4b /hash.c
parent812550b977e2114d74212ee211e520baee8760f3 (diff)
* hash.c (ruby_setenv): calculate total env block size for win32.
* test/ruby/test_env.rb: add test for above patch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index b303211db7..e847b4dd3a 100644
--- a/hash.c
+++ b/hash.c
@@ -2194,6 +2194,20 @@ envix(const char *nam)
}
#endif
+#if defined(_WIN32)
+static int
+getenvsize(char* p)
+{
+ char prev = *p++;
+ int len = 1;
+ for (; prev || *p; p++) {
+ prev = *p;
+ len++;
+ }
+ return len;
+}
+#endif
+
void
ruby_setenv(const char *name, const char *value)
{
@@ -2208,7 +2222,7 @@ ruby_setenv(const char *name, const char *value)
if (value) {
char* p = GetEnvironmentStringsA();
if (p) {
- if (strlen(value) + strlen(p) >= 32767) goto fail;
+ if (strlen(name) + 1 + strlen(value) + getenvsize(p) >= 32767) goto fail;
} else {
if (strlen(value) >= 5120) goto fail;
}