diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-01 01:25:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-01 01:25:09 +0000 |
commit | fd2086a7556795eb5b81b5268db5b2ac8c8d2e91 (patch) | |
tree | 0d7e5530f25afdd5dfefa4a7564ebe0eb82aa0e0 | |
parent | 73a59934178cb8e0aa73a7ee27250304ed532312 (diff) | |
download | ruby-fd2086a7556795eb5b81b5268db5b2ac8c8d2e91.tar.gz ruby-fd2086a7556795eb5b81b5268db5b2ac8c8d2e91.tar.xz ruby-fd2086a7556795eb5b81b5268db5b2ac8c8d2e91.zip |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@1715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ruby.c | 33 |
2 files changed, 25 insertions, 16 deletions
@@ -1,3 +1,11 @@ +Sat Sep 1 09:50:54 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> + + * 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. + Wed Aug 29 02:18:53 2001 Yukihiro Matsumoto <matz@ruby-lang.org> * parse.y (yylex): ternary ? can be followed by newline. @@ -60,7 +60,7 @@ static VALUE do_split = Qfalse; static char *script; -static int origargc; +static int origargc, origarglen; static char **origargv; static void @@ -885,25 +885,13 @@ 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 StringValue(val); s = RSTRING(val)->ptr; i = RSTRING(val)->len; #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); @@ -1026,6 +1014,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) |