summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/dir.c b/dir.c
index 3ddcc8fdf9..93458a3b74 100644
--- a/dir.c
+++ b/dir.c
@@ -482,7 +482,7 @@ push_braces(ary, s)
VALUE ary;
char *s;
{
- char buf[MAXPATHLEN];
+ char buffer[MAXPATHLEN], *buf = buffer;
char *p, *t, *b;
char *lbrace, *rbrace;
@@ -504,6 +504,9 @@ push_braces(ary, s)
}
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 @@ push_braces(ary, s)
strcpy(b+(p-t), rbrace+1);
push_braces(ary, buf);
}
+ if (buf != buffer)
+ free(buf);
}
else {
push_globs(ary, s);
@@ -530,17 +535,15 @@ dir_s_glob(dir, str)
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);
- }
ary = rb_ary_new();
+ if (RSTRING(str)->len >= MAXPATHLEN)
+ buf = xmalloc(RSTRING(str)->len + 1);
p = RSTRING(str)->ptr;
pend = p + RSTRING(str)->len;
@@ -567,6 +570,8 @@ dir_s_glob(dir, str)
}
/* else unmatched braces */
}
+ if (buf != buffer)
+ free(buf);
return ary;
}