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

ruby-changes:19093

From: arton <ko1@a...>
Date: Sun, 20 Mar 2011 01:34:06 +0900 (JST)
Subject: [ruby-changes:19093] Ruby:r31132 (trunk): * hash.c (ruby_setenv): check env process block size with OS ver.

arton	2011-03-20 01:33:59 +0900 (Sun, 20 Mar 2011)

  New Revision: 31132

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

  Log:
    * hash.c (ruby_setenv): check env process block size with OS ver.
    * win32/win32.c: export rb_w32_osver for above patch.
    * include/ruby/win32.h: declare rb_w32_osver for Win32 Libs.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/include/ruby/win32.h
    trunk/win32/win32.c

Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 31131)
+++ include/ruby/win32.h	(revision 31132)
@@ -271,6 +271,7 @@
 extern void   rb_w32_free_environ(char **);
 extern int    rb_w32_map_errno(DWORD);
 extern char * WSAAPI rb_w32_inet_ntop(int,void *,char *,size_t);
+extern DWORD  rb_w32_osver(void); 
 
 extern int chown(const char *, int, int);
 extern int rb_w32_uchown(const char *, int, int);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31131)
+++ ChangeLog	(revision 31132)
@@ -1,3 +1,9 @@
+Sun Mar 20 01:39:48 2011  Tajima Akio <artonx@y...>
+
+	* hash.c (ruby_setenv): check env process block size with OS ver.
+	* win32/win32.c: export rb_w32_osver for above patch.
+	* include/ruby/win32.h: declare rb_w32_osver for Win32 Libs.
+
 Sat Mar 19 18:35:05 2011  Tajima Akio <artonx@y...>
 
 	* hash.c (ruby_setenv): calculate total env block size for win32.
@@ -6,7 +12,7 @@
 Sat Mar 19 17:14:46 2011  Tajima Akio <artonx@y...>
 
 	* hash.c (ruby_setenv): checking with max process environment 
-	  block size fow Win32. 32767 for 2000/XP, 2003. if failed to
+	  block size for Win32. 32767 for 2000/XP, 2003. if failed to
 	  read the block, then checking with 5120 for earlier Windows.
 
 Sat Mar 19 12:30:25 2011  Tanaka Akira  <akr@f...>
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 31131)
+++ win32/win32.c	(revision 31132)
@@ -252,7 +252,7 @@
 }
 #endif
 
-static DWORD
+DWORD
 rb_w32_osver(void)
 {
     return osver.dwMajorVersion;
Index: hash.c
===================================================================
--- hash.c	(revision 31131)
+++ hash.c	(revision 31132)
@@ -2195,13 +2195,18 @@
 #endif
 
 #if defined(_WIN32)
-static int
-getenvsize(char* p)
+static size_t
+getenvsize(const char* p)
 {
-    char* porg = p;
-    while (*p || *(p + 1)) ++p;
+    const char* porg = p;
+    while (*p++) p += strlen(p) + 1;
     return p - porg + 1;
 }
+static size_t
+getenvblocksize()
+{
+    return (rb_w32_osver() >= 5) ? 32767 : 5120;
+}
 #endif
 
 void
@@ -2216,11 +2221,10 @@
 	rb_sys_fail("ruby_setenv");
     }
     if (value) {
-	char* p = GetEnvironmentStringsA();
-	if (p) {
-	    if (strlen(name) + 1 + strlen(value) + getenvsize(p) >= 32767) goto fail;
-	} else {
-	    if (strlen(value) >= 5120) goto fail;
+	const char* p = GetEnvironmentStringsA();
+	if (!p) goto fail; /* never happen */
+	if (strlen(name) + 2 + strlen(value) + getenvsize(p) >= getenvblocksize()) {
+	    goto fail;  /* 2 for '=' & '\0' */
 	}
 	buf = rb_sprintf("%s=%s", name, value);
     }

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

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