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
commitd1ad995dfd6969d1140cfabe0c86a85fe8fbe63e (patch)
tree0d7e5530f25afdd5dfefa4a7564ebe0eb82aa0e0 /ruby.c
parentb47a99485bf9937ceb5f137916bc1fd85cc2304f (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/trunk@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 a34c0a2..e123917 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
@@ -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)