diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-28 10:24:57 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-28 10:24:57 +0000 |
commit | 89133fafe70c7a3b5d04cf2be028e1eacc6e0447 (patch) | |
tree | f57ba2b0af109c4854b4d61c07bbb47a07e9c11f /dir.c | |
parent | eb2aca18dcb4baccf0de494f53fed4ec68e9af27 (diff) |
merge revision(s) 62989:
dir.c: check NUL bytes
* dir.c (GlobPathValue): should be used in rb_push_glob only.
other methods should use FilePathValue.
https://hackerone.com/reports/302338
* dir.c (rb_push_glob): expand GlobPathValue
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -449,15 +449,6 @@ static const rb_data_type_t dir_data_type = { static VALUE dir_close(VALUE); -#define GlobPathValue(str, safe) \ - /* can contain null bytes as separators */ \ - (!RB_TYPE_P((str), T_STRING) ? \ - (void)FilePathValue(str) : \ - (void)(check_safe_glob((str), (safe)), \ - check_glob_encoding(str), (str))) -#define check_safe_glob(str, safe) ((safe) ? rb_check_safe_obj(str) : (void)0) -#define check_glob_encoding(str) rb_enc_check((str), rb_enc_from_encoding(rb_usascii_encoding())) - static VALUE dir_s_alloc(VALUE klass) { @@ -506,7 +497,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir) } } - GlobPathValue(dirname, FALSE); + FilePathValue(dirname); orig = rb_str_dup_frozen(dirname); dirname = rb_str_encode_ospath(dirname); dirname = rb_str_dup_frozen(dirname); @@ -2185,7 +2176,14 @@ rb_push_glob(VALUE str, int flags) /* '\0' is delimiter */ long offset = 0; VALUE ary; - GlobPathValue(str, TRUE); + /* can contain null bytes as separators */ + if (!RB_TYPE_P((str), T_STRING)) { + FilePathValue(str); + } + else { + rb_check_safe_obj(str); + rb_enc_check(str, rb_enc_from_encoding(rb_usascii_encoding())); + } ary = rb_ary_new(); while (offset < RSTRING_LEN(str)) { @@ -2215,7 +2213,7 @@ dir_globs(long argc, const VALUE *argv, int flags) for (i = 0; i < argc; ++i) { int status; VALUE str = argv[i]; - GlobPathValue(str, TRUE); + FilePathValue(str); status = push_glob(ary, str, flags); if (status) GLOB_JUMP_TAG(status); } |