[前][次][番号順一覧][スレッド一覧]

ruby-changes:19092

From: arton <ko1@a...>
Date: Sat, 19 Mar 2011 20:34:49 +0900 (JST)
Subject: [ruby-changes:19092] Ruby:r31130 (trunk): * hash.c (ruby_setenv): calculate total env block size for win32.

arton	2011-03-19 18:28:49 +0900 (Sat, 19 Mar 2011)

  New Revision: 31130

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31130

  Log:
    * hash.c (ruby_setenv): calculate total env block size for win32.
    * test/ruby/test_env.rb: add test for above patch.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_env.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31129)
+++ ChangeLog	(revision 31130)
@@ -1,3 +1,8 @@
+Sat Mar 19 18:35:05 2011  Tajima Akio <artonx@y...>
+
+	* hash.c (ruby_setenv): calculate total env block size for win32.
+	* test/ruby/test_env.rb: add test for above patch.
+
 Sat Mar 19 17:14:46 2011  Tajima Akio <artonx@y...>
 
 	* hash.c (ruby_setenv): checking with max process environment 
Index: hash.c
===================================================================
--- hash.c	(revision 31129)
+++ hash.c	(revision 31130)
@@ -2194,6 +2194,20 @@
 }
 #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 @@
     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;
 	}
Index: test/ruby/test_env.rb
===================================================================
--- test/ruby/test_env.rb	(revision 31129)
+++ test/ruby/test_env.rb	(revision 31130)
@@ -387,4 +387,16 @@
       assert_equal(huge_value, ENV["foo"])
     end
   end
+
+  if /mswin|mingw/ =~ RUBY_PLATFORM
+    def test_win32_blocksize
+      len = 32767 - ENV.to_a.flatten.inject(0) {|r,e| r + e.size + 2 }
+      val = "bar" * 1000
+      key = nil
+      1.upto(12) {|i|
+        ENV[key] = val while (len -= val.size + (key="foo#{len}").size + 2) > 0
+        assert_raise(Errno::EINVAL) { ENV[key] = val }
+      }
+    end
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]