From 11e4052295ade5bfa68f9f4b1c4b99edcfbbedc7 Mon Sep 17 00:00:00 2001 From: arton Date: Sat, 19 Mar 2011 16:33:59 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index f28b15f5f4..8a3e8fe44f 100644 --- a/hash.c +++ b/hash.c @@ -2195,13 +2195,18 @@ envix(const char *nam) #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 @@ ruby_setenv(const char *name, const char *value) 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); } -- cgit v1.2.3