summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--ruby.c33
2 files changed, 25 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 69326a226f..425071002e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/ruby.c b/ruby.c
index a34c0a2974..e12391762d 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)