diff options
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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; } |