ruby-changes:34693
From: ngoto <ko1@a...>
Date: Fri, 11 Jul 2014 00:22:28 +0900 (JST)
Subject: [ruby-changes:34693] ngoto:r46776 (trunk): * hash.c (ruby_setenv): Fix TestEnv#test_aset failure on Solaris 9.
ngoto 2014-07-11 00:22:07 +0900 (Fri, 11 Jul 2014) New Revision: 46776 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46776 Log: * 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. Modified files: trunk/ChangeLog trunk/hash.c Index: ChangeLog =================================================================== --- ChangeLog (revision 46775) +++ ChangeLog (revision 46776) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 10 23:51:36 2014 Naohisa Goto <ngotogenome@g...> + + * 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. + Thu Jul 10 15:02:55 2014 Nobuyoshi Nakada <nobu@r...> * vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack Index: hash.c =================================================================== --- hash.c (revision 46775) +++ hash.c (revision 46776) @@ -2729,6 +2729,10 @@ getenvblocksize() https://github.com/ruby/ruby/blob/trunk/hash.c#L2729 { 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 https://github.com/ruby/ruby/blob/trunk/hash.c#L2802 #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 https://github.com/ruby/ruby/blob/trunk/hash.c#L2826 } } 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/