summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-13 04:04:33 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-13 04:04:33 +0000
commitbab2d449bbe941e0f8932c3f6d2df944b90cc8c2 (patch)
treed822db91956c6bcd677a60cd7dab35c733da1daa
parent68c81d5b4e6298d84c99c88e027ee0bfe2105acc (diff)
* hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--hash.c29
2 files changed, 17 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 3753f49..6dd69a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Jun 13 13:01:05 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186]
+
Mon Jun 13 01:54:20 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (sigexit): call rb_thread_signal_exit() instead of
diff --git a/hash.c b/hash.c
index 3f1ebea..f987181 100644
--- a/hash.c
+++ b/hash.c
@@ -1837,27 +1837,24 @@ ruby_setenv(name, value)
tmpenv[max] = 0;
environ = tmpenv; /* tell exec where it is now */
}
- if (!value) {
- if (environ != origenviron) {
- char **envp = origenviron;
- while (*envp && *envp != environ[i]) envp++;
- if (!*envp)
- free(environ[i]);
- }
- while (environ[i]) {
- environ[i] = environ[i+1];
- i++;
+ if (environ[i]) {
+ char **envp = origenviron;
+ while (*envp && *envp != environ[i]) envp++;
+ if (!*envp)
+ free(environ[i]);
+ if (!value) {
+ while (environ[i]) {
+ environ[i] = environ[i+1];
+ i++;
+ }
+ return;
}
- return;
}
- if (!environ[i]) { /* does not exist yet */
+ else { /* does not exist yet */
+ if (!value) return;
REALLOC_N(environ, char*, i+2); /* just expand it a bit */
environ[i+1] = 0; /* make sure it's null terminated */
}
- else {
- if (environ[i] != origenviron[i])
- free(environ[i]);
- }
environ[i] = ALLOC_N(char, strlen(name) + strlen(value) + 2);
#ifndef MSDOS
sprintf(environ[i],"%s=%s",name,value); /* all that work just for this */