Created
March 19, 2011 08:26
-
-
Save arton/877331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- hash.c~ Tue Mar 08 23:06:17 2011 | |
+++ hash.c Sat Mar 19 17:24:57 2011 | |
@@ -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) | |
{ | |
@@ -2206,7 +2220,12 @@ ruby_setenv(const char *name, const char | |
rb_sys_fail("ruby_setenv"); | |
} | |
if (value) { | |
- if (strlen(value) > 5120) goto fail; | |
+ char* p = GetEnvironmentStringsA(); | |
+ if (p) { | |
+ if (strlen(value) + getenvsize(p) >= 32767) goto fail; | |
+ } else { | |
+ if (strlen(value) >= 5120) goto fail; | |
+ } | |
buf = rb_sprintf("%s=%s", name, value); | |
} | |
else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment