summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-09-01 01:25:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-09-01 01:25:09 +0000
commit3307221f3496f37ed546f9b6f871ce930ed2fb85 (patch)
tree7561070027ce8fcbe9468e7837d60064086cbd12 /ruby.c
parent27d383561cf22ce6275a07fddf14d2cf2e3944c3 (diff)
* ruby.c (set_arg0): prevent SEGV when val is longer than the
original arguments. * ruby.c (ruby_process_options): initialize total length of original arguments at first. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/ruby.c b/ruby.c
index c47e1c7e8b..43cb67a5d3 100644
--- a/ruby.c
+++ b/ruby.c
@@ -60,7 +60,7 @@ static VALUE do_split = Qfalse;
static char *script;
-static int origargc;
+static int origargc, origarglen;
static char **origargv;
static void
@@ -882,23 +882,11 @@ set_arg0(val, id)
static int len;
if (origargv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized");
-#ifndef __hpux
- if (len == 0) {
- s = origargv[0];
- s += strlen(s);
- /* See if all the arguments are contiguous in memory */
- for (i = 1; i < origargc; i++) {
- if (origargv[i] == s + 1)
- s += strlen(++s); /* this one is ok too */
- }
- len = s - origargv[0];
- }
-#endif
s = rb_str2cstr(val, &i);
#ifndef __hpux
- if (i < len) {
- memcpy(origargv[0], s, i);
- origargv[0][i] = '\0';
+ if (i >= len) {
+ memcpy(origargv[0], s, len);
+ origargv[0][len] = '\0';
}
else {
memcpy(origargv[0], s, i);
@@ -1020,6 +1008,19 @@ ruby_process_options(argc, argv)
char **argv;
{
origargc = argc; origargv = argv;
+#ifndef __hpux
+ if (origarglen == 0) {
+ int i;
+ char *s = origargv[0];
+ s += strlen(s);
+ /* See if all the arguments are contiguous in memory */
+ for (i = 1; i < origargc; i++) {
+ if (origargv[i] == s + 1)
+ s += strlen(++s); /* this one is ok too */
+ }
+ origarglen = s - origargv[0];
+ }
+#endif
ruby_script(argv[0]); /* for the time being */
rb_argv0 = rb_progname;
#if defined(USE_DLN_A_OUT)