summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-10 15:22:07 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-10 15:22:07 +0000
commit90b1b2e607fc0761a9e19af9d10a1f5b499e5894 (patch)
tree2ca662b98f1948e1b3e957ba32228eb8da220631 /hash.c
parent813ad48975420867ccd1919972ba138f13c6f6e5 (diff)
* hash.c (ruby_setenv): Fix TestEnv#test_aset failure on Solaris 9.
When name contains '=', ruby_setenv raises Errno::EINVAL. That is the same behavior as Solaris 10. NULL check for malloc return value is also added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index 4bf0ae3715..c600fd11ab 100644
--- a/hash.c
+++ b/hash.c
@@ -2729,6 +2729,10 @@ getenvblocksize()
{
return (rb_w32_osver() >= 5) ? 32767 : 5120;
}
+#endif
+
+#if defined(_WIN32) || \
+ (defined(__sun) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV)))
NORETURN(static void invalid_envname(const char *name));
@@ -2798,10 +2802,22 @@ ruby_setenv(const char *name, const char *value)
#endif
}
#elif defined __sun
- size_t len;
- char **env_ptr, *str;
+ /* Solaris 9 (or earlier) does not have setenv(3C) and unsetenv(3C). */
+ /* The below code was tested on Solaris 10 by:
+ % ./configure ac_cv_func_setenv=no ac_cv_func_unsetenv=no
+ */
+ size_t len, mem_size;
+ char **env_ptr, *str, *mem_ptr;
+ check_envname(name);
len = strlen(name);
+ if (value) {
+ mem_size = len + strlen(value) + 2;
+ mem_ptr = malloc(mem_size);
+ if (mem_ptr == NULL)
+ rb_sys_fail_str(rb_sprintf("malloc("PRIuSIZE")", mem_size));
+ snprintf(mem_ptr, mem_size, "%s=%s", name, value);
+ }
for (env_ptr = GET_ENVIRON(environ); (str = *env_ptr) != 0; ++env_ptr) {
if (!strncmp(str, name, len) && str[len] == '=') {
if (!in_origenv(str)) free(str);
@@ -2810,10 +2826,10 @@ ruby_setenv(const char *name, const char *value)
}
}
if (value) {
- str = malloc(len += strlen(value) + 2);
- snprintf(str, len, "%s=%s", name, value);
- if (putenv(str))
+ if (putenv(mem_ptr)) {
+ free(mem_ptr);
rb_sys_fail_str(rb_sprintf("putenv(%s)", name));
+ }
}
#else /* WIN32 */
size_t len;