Bug #3812: (mswin|mingw) ENV[]=3D fails silently to set huge values
http://redmine.ruby-lang.org/issues/show/3812

Author: Peter Weldon
Status: Open, Priority: Normal
ruby -v: ruby 1.9.3dev (2010-09-08 trunk 29195) [i386-mswin32_100]

On mswin&mingw the size of an environment key, value pair is bounded by _=
MAX_ENV. Calls to putenv() or _putenv() that exceed this will fail and no=
t set the value.

Trivial patch that adds test case and error checking to raise Errno::EINV=
AL on failure.


----------------------------------------
http://redmine.ruby-lang.org
Y29tbWl0IDAzYjliOTliZWFhNTVmMzhiYWMxY2NiMTNjM2IwYzE5YWM0NjEw
MTQKQXV0aG9yOiBQZXRlciBXZWxkb24gPHBldGVyLndlbGRvbkBudWxsLm5l
dD4KRGF0ZTogICBUdWUgU2VwIDcgMTU6NTE6NTMgMjAxMCAtMDcwMAoKICAg
IGhhc2guYyAocnVieV9zZXRlbnYpOiBBZGQgZXJyb3IgY2hlY2tpbmcgZm9y
IHdpbjMyCgpkaWZmIC0tZ2l0IGEvaGFzaC5jIGIvaGFzaC5jCmluZGV4IDhi
YmE1ODYuLjc3MzAxZTQgMTAwNjQ0Ci0tLSBhL2hhc2guYworKysgYi9oYXNo
LmMKQEAgLTIxNDEsMjcgKzIxNDEsMTkgQEAgcnVieV9zZXRlbnYoY29uc3Qg
Y2hhciAqbmFtZSwgY29uc3QgY2hhciAqdmFsdWUpCiAjaWYgZGVmaW5lZChf
V0lOMzIpCiAgICAgaW50IGxlbjsKICAgICBjaGFyICpidWY7Ci0gICAgaWYg
KHN0cmNocihuYW1lLCAnPScpKSB7Ci0JZXJybm8gPSBFSU5WQUw7Ci0JcmJf
c3lzX2ZhaWwoInJ1Ynlfc2V0ZW52Iik7Ci0gICAgfQotICAgIGlmICh2YWx1
ZSkgewotCWxlbiA9IHN0cmxlbihuYW1lKSArIDEgKyBzdHJsZW4odmFsdWUp
ICsgMTsKLQlidWYgPSBBTExPQ0FfTihjaGFyLCBsZW4pOwotCXNucHJpbnRm
KGJ1ZiwgbGVuLC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