Skip to content

Instantly share code, notes, and snippets.

@arton
Created March 19, 2011 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arton/877331 to your computer and use it in GitHub Desktop.
Save arton/877331 to your computer and use it in GitHub Desktop.
--- 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