diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-02 15:08:53 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-02 15:08:53 +0900 |
commit | 6f206b8ec6f945804c56cf8249739c6e94ed65f6 (patch) | |
tree | 8e04d964baa3cd07239dcaeb35ed41d113c55c39 /dir.c | |
parent | 633ae3278ecce7c2b98fa1aa6106f963894c538a (diff) |
Prohibit nul-separated glob pattern [Feature #14643] (#2419)
Notes
Notes:
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 31 |
1 files changed, 7 insertions, 24 deletions
@@ -2694,41 +2694,24 @@ push_glob(VALUE ary, VALUE str, VALUE base, int flags) static VALUE rb_push_glob(VALUE str, VALUE base, int flags) /* '\0' is delimiter */ { - long offset = 0; - long len; VALUE ary; - int warned = FALSE; + int status; /* can contain null bytes as separators */ - if (!RB_TYPE_P((str), T_STRING)) { + if (!RB_TYPE_P(str, T_STRING)) { FilePathValue(str); } + else if (!rb_str_to_cstr(str)) { + rb_raise(rb_eArgError, "nul-separated glob pattern is deprecated"); + } else { rb_check_safe_obj(str); rb_enc_check(str, rb_enc_from_encoding(rb_usascii_encoding())); } ary = rb_ary_new(); - while (offset < (len = RSTRING_LEN(str))) { - int status; - long rest = len - offset; - const char *pbeg = RSTRING_PTR(str), *p = pbeg + offset; - const char *pend = memchr(p, '\0', rest); - if (pend) { - if (!warned) { - rb_warn("use glob patterns list instead of nul-separated patterns"); - warned = TRUE; - } - rest = ++pend - p; - offset = pend - pbeg; - } - else { - offset = len; - } - status = push_glob(ary, rb_str_subseq(str, p-pbeg, rest), - base, flags); - if (status) GLOB_JUMP_TAG(status); - } + status = push_glob(ary, str, base, flags); + if (status) GLOB_JUMP_TAG(status); return ary; } |