[#7102] Ruby 1.3.4-990611 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.4-990611 is out, check out:

20 messages 1999/06/11

[#7223] Ruby 1.3.4-990625 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.4-990625 is out, check out:

14 messages 1999/06/25
[#7224] -Wl,-rpath on Linux (Re: Ruby 1.3.4-990625) — Ryo HAYASAKA <hayasaka@...21.u-aizu.ac.jp> 1999/06/25

早坂@会津大学です。

[ruby-dev:7157] Dir.glob

From: Tadayoshi Funaba <tadf@...>
Date: 1999-06-21 14:39:46 UTC
List: ruby-dev #7157
ふなばです。
# 届いてないようなので再送です。

p Dir.glob('*'*1024)

とした場合にコアダンプする可能性があります (ぴったり MAXPATHLEN のとき)。


--- dir.c.orig	Mon May 10 17:22:45 1999
+++ dir.c	Sun Jun 20 12:09:02 1999
@@ -536,7 +536,7 @@
     VALUE ary;
 
     Check_SafeStr(str);
-    if (RSTRING(str)->len > MAXPATHLEN) {
+    if (RSTRING(str)->len >= MAXPATHLEN) {
 	rb_raise(rb_eArgError, "pathname too long (%d bytes)",
 		 RSTRING(str)->len);
     }


できれば制限はないほうがうれしいので、ためしに機械的に修正してみる、の版。


--- dir.c.orig	Mon May 10 17:22:45 1999
+++ dir.c	Mon Jun 21 12:39:41 1999
@@ -482,7 +482,7 @@
     VALUE ary;
     char *s;
 {
-    char buf[MAXPATHLEN];
+    char buffer[MAXPATHLEN], *buf = buffer;
     char *p, *t, *b;
     char *lbrace, *rbrace;
 
@@ -504,6 +504,9 @@
     }
 
     if (lbrace) {
+	int len = strlen(s);
+	if (len >= MAXPATHLEN)
+	    buf = xmalloc(len + 1);
 	memcpy(buf, s, lbrace-s);
 	b = buf + (lbrace-s);
 	p = lbrace;
@@ -517,6 +520,8 @@
 	    strcpy(b+(p-t), rbrace+1);
 	    push_braces(ary, buf);
 	}
+	if (buf != buffer)
+	    free(buf);
     }
     else {
 	push_globs(ary, s);
@@ -530,16 +535,14 @@
     VALUE dir, str;
 {
     char *p, *pend;
-    char buf[MAXPATHLEN];
+    char buffer[MAXPATHLEN], *buf = buffer;
     char *t, *t0;
     int nest;
     VALUE ary;
 
     Check_SafeStr(str);
-    if (RSTRING(str)->len > MAXPATHLEN) {
-	rb_raise(rb_eArgError, "pathname too long (%d bytes)",
-		 RSTRING(str)->len);
-    }
+    if (RSTRING(str)->len >= MAXPATHLEN)
+	buf = xmalloc(RSTRING(str)->len + 1);
     ary = rb_ary_new();
 
     p = RSTRING(str)->ptr;
@@ -567,6 +570,8 @@
 	}
 	/* else unmatched braces */
     }
+    if (buf != buffer)
+	free(buf);
     return ary;
 }

 
[57,22,26,17,78,21,7,9,29,11,10,2,72,59,25,13,10,79,24,9,10,8,4,30,13].
  each_with_index{|x,i| $><<(x^'scientificophilosophical!'[i]).chr}

ふなば ただよし

In This Thread

Prev Next