aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
Commit message (Collapse)AuthorAgeFilesLines
* IO#set_encoding_by_bom should err when encoding is already setNobuyoshi Nakada2019-12-151-0/+4
| | | | Except for ASCII-8BIT. [Bug #16422]
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-8/+0
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-3/+0
| | | | | | | | | | | | | | | | | This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd.
* delete unused functions卜部昌平2019-11-141-16/+0
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* builtin.h must be included *AFTER* vm_core.hNobuyoshi Nakada2019-11-081-15/+19
|
* Renamed `load_*.inc` as `*.rbinc` to utilize a suffix ruleNobuyoshi Nakada2019-11-081-1/+1
|
* Define IO#read/write_nonblock with builtins.Koichi Sasada2019-11-081-6/+11
| | | | | | | IO#read/write_nonblock methods are defined in prelude.rb with special private method __read/write_nonblock to reduce keyword parameters overhead. We can move them into io.rb with builtin functions.
* io.c (rb_update_max_fd): fail with a negative file descripterYusuke Endoh2019-10-131-1/+1
| | | | | | Coverity Scan points out that ext/socket/unixsocket.c may pass -1 to rb_update_max_fd. I'm unsure whether it can happen actually or not, but it would be good for the function to reject a negative value.
* io.c (NUM2IOCTLREQ): Accept a value more than INT_MAXYusuke Endoh2019-10-111-1/+1
| | | | | | | | ioctl accepts int as request arguments on some platforms, but some requests are more than INT_MAX, e.g., RNDGETENTCNT(0x80045200). Passing (0x80045200 | (-1 << 32)) may work around the issue, but it may not work on a platform where ioctl accepts unsigned long. So this change uses NUM2LONG and then casts it to int.
* Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-09-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function.
* Fixed the function signature to rb_rescue2Nobuyoshi Nakada2019-09-111-1/+2
|
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-1/+1
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* drop-in type check for rb_define_global_function卜部昌平2019-08-291-4/+4
| | | | | | We can check the function pointer passed to rb_define_global_function like we do so in rb_define_method. It turns out that almost anybody is misunderstanding the API.
* delete `$` sign from C identifiers卜部昌平2019-08-271-3/+3
| | | | | They lack portability. See also https://travis-ci.org/shyouhei/ruby/jobs/577164015
* rb_define_hooked_variable now free from ANYARGS卜部昌平2019-08-271-1/+13
| | | | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit uses rb_gvar_getter_t / rb_gvar_setter_t for rb_define_hooked_variable / rb_define_virtual_variable which revealed lots of function prototype inconsistencies. Some of them were literally decades old, going back to dda5dc00cff334cac373096d444a0fd59e716124.
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-4/+8
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
* rb_rescue / rb_rescue2 now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
* io.c: make ioctl_req_t int in AndroidYusuke Endoh2019-08-201-1/+1
| | | | | | The second argument of ioctl seems to be int in Android. Android is not a supported platform, but this one-line change allows ruby to build by Android NDK r20.
* io.c: export rb_io_extract_modeencNobuyoshi Nakada2019-08-141-1/+1
| | | | | | * include/ruby/io.h (rb_io_enc_t): add typedef. * io.c (rb_io_extract_modeenc): export.
* UTF LE is fixed at least the first 2 bytesNobuyoshi Nakada2019-08-131-5/+2
| | | | | * io.c (io_strip_bom): if the first 2 bytes are 0xFF0xFE, it should be a little-endian UTF, 16 or 32. [Bug #16099]
* #include <> for system headersNobuyoshi Nakada2019-08-091-1/+1
|
* * expand tabs.git2019-07-311-2/+2
|
* Do not change IO.pipe encodings if encodings explicitly givenJeremy Evans2019-07-301-1/+1
| | | | | | | | This commit makes it so that if the binmode option is given with any encoding arguments, the reader and writer IO objects are not set to binary encoding. Fixes [Bug #12989]
* Passing `binmode: true` to `IO.pipe` should behave like `binmode`Aaron Patterson2019-07-301-0/+6
| | | | | | | | | | | When passing `binmode: true` to `IO.pipe`, it should behave the same way as calling `binmode` on each of the file handles. It should set the file to binmode *and* set the encoding to binary on the file. Before this commit, passing `binmode: true` to `IO.pipe` would make `binmode?` return `true`, but the file's encoding would remain the same as the default encoding. Passing `binmode: true` should make `binmode?` return `true` *and* set the encoding to binary.
* io.c (rb_file_open_internal): initialize all the fieldsYusuke Endoh2019-07-141-0/+2
| | | | Just for case. This will suppress the warning of Coverity Scan.
* * expand tabs.git2019-07-141-1/+1
|
* Avoid io_tell whose return value is not usedYusuke Endoh2019-07-141-1/+1
| | | | | In this case, flush_before_seek is enough. This change will suppress a warning of Coverity Scan.
* * expand tabs.git2019-07-111-4/+4
|
* Check exception flag as a bool [Bug #15987]Nobuyoshi Nakada2019-07-111-20/+16
|
* O_EXCL has no meaning for fdopenNobuyoshi Nakada2019-06-281-1/+1
| | | | | "exclusive access mode is not supported" exception has resulted in empty "rubyheap-*.json" files after test/objspace/test_objspace.rb.
* IO#set_encoding_by_bomNobuyoshi Nakada2019-06-131-3/+41
| | | | | * io.c (rb_io_set_encoding_by_bom): IO#set_encoding_by_bom to set the encoding by BOM if exists. [Bug #15210]
* Suppress warnings by gcc 9.1Nobuyoshi Nakada2019-06-081-3/+4
|
* io.c: fold very very long linesNobuyoshi Nakada2019-06-081-5/+20
|
* Fixed about ARGF.linenoNobuyoshi Nakada2019-05-051-2/+10
| | | | [Bug #15823]
* eliminate use of freed memoryUrabe, Shyouhei2019-04-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rb_io_fptr_finalize_internal frees the memory region. ================================================================= ==85264==ERROR: AddressSanitizer: heap-use-after-free on address 0x610000000d8c at pc 0x5608e38077f7 bp 0x7ffee12d5440 sp 0x7ffee12d5438 READ of size 4 at 0x610000000d8c thread T0 #0 0x5608e38077f6 in rb_io_memsize io.c:4749:24 #1 0x5608e37a0481 in obj_memsize_of gc.c:3547:14 #2 0x5608e37a4f30 in check_rvalue_consistency gc.c:1107:2 #3 0x5608e37a2624 in RVALUE_OLD_P gc.c:1218:5 #4 0x5608e37a5bae in rb_gc_force_recycle gc.c:6652:18 #5 0x5608e38191f9 in rb_f_backquote io.c:9021:5 #6 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12 #7 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11 #8 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12 #9 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9 #10 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13 #11 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12 #12 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11 #13 0x5608e3d06cf5 in vm_exec_core insns.def:789:11 #14 0x5608e3d43700 in rb_vm_exec vm.c:1892:22 #15 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11 #16 0x5608e37620ca in ruby_exec_internal eval.c:262:2 #17 0x5608e376198b in ruby_exec_node eval.c:326:12 #18 0x5608e37617d0 in ruby_run_node eval.c:318:25 #19 0x5608e35c9486 in main main.c:42:9 #20 0x7f62e9421b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 #21 0x5608e3522289 in _start (miniruby+0x15f289) 0x610000000d8c is located 76 bytes inside of 192-byte region [0x610000000d40,0x610000000e00) freed by thread T0 here: #0 0x5608e359a2ed in free (miniruby+0x1d72ed) #1 0x5608e37af421 in objspace_xfree gc.c:9591:5 #2 0x5608e37af3da in ruby_sized_xfree gc.c:9687:2 #3 0x5608e3799ac8 in ruby_xfree gc.c:9694:5 #4 0x5608e380746d in rb_io_fptr_finalize_internal io.c:4728:5 #5 0x5608e38191ed in rb_f_backquote io.c:9020:5 #6 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12 #7 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11 #8 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12 #9 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9 #10 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13 #11 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12 #12 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11 #13 0x5608e3d06cf5 in vm_exec_core insns.def:789:11 #14 0x5608e3d43700 in rb_vm_exec vm.c:1892:22 #15 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11 #16 0x5608e37620ca in ruby_exec_internal eval.c:262:2 #17 0x5608e376198b in ruby_exec_node eval.c:326:12 #18 0x5608e37617d0 in ruby_run_node eval.c:318:25 #19 0x5608e35c9486 in main main.c:42:9 #20 0x7f62e9421b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 previously allocated by thread T0 here: #0 0x5608e359a56d in malloc (miniruby+0x1d756d) #1 0x5608e37aed12 in objspace_xmalloc0 gc.c:9416:5 #2 0x5608e37aebe7 in ruby_xmalloc0 gc.c:9600:12 #3 0x5608e37aea8b in ruby_xmalloc_body gc.c:9609:12 #4 0x5608e37a6d64 in ruby_xmalloc gc.c:11469:12 #5 0x5608e380e4b4 in rb_io_fptr_new io.c:8040:19 #6 0x5608e380e446 in rb_io_make_open_file io.c:8077:10 #7 0x5608e3850ea0 in pipe_open io.c:6707:5 #8 0x5608e384edb4 in pipe_open_s io.c:6772:12 #9 0x5608e381910b in rb_f_backquote io.c:9014:12 #10 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12 #11 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11 #12 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12 #13 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9 #14 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13 #15 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12 #16 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11 #17 0x5608e3d06cf5 in vm_exec_core insns.def:789:11 #18 0x5608e3d43700 in rb_vm_exec vm.c:1892:22 #19 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11 #20 0x5608e37620ca in ruby_exec_internal eval.c:262:2 #21 0x5608e376198b in ruby_exec_node eval.c:326:12 #22 0x5608e37617d0 in ruby_run_node eval.c:318:25 #23 0x5608e35c9486 in main main.c:42:9 #24 0x7f62e9421b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 SUMMARY: AddressSanitizer: heap-use-after-free io.c:4749:24 in rb_io_memsize Shadow bytes around the buggy address: 0x0c207fff8160: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c207fff8170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c207fff8180: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c207fff8190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c207fff81a0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd =>0x0c207fff81b0: fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c207fff81c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c207fff81d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c207fff81e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c207fff81f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c207fff8200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==85264==ABORTING
* io.c: warn non-nil $,nobu2019-04-181-1/+11
| | | | | | | | * array.c (rb_ary_join_m): warn use of non-nil $,. * io.c (rb_output_fs_setter): warn when set to non-nil value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adjusted stylesnobu2019-04-101-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting all commits from r67479 to r67496 because of CI failureskazu2019-04-101-2/+1
| | | | | | | | Because hard to specify commits related to r67479 only. So please commit again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adjusted stylesnobu2019-04-101-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] fix markups [ci skip]nobu2019-03-221-174/+160
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: chomp CR at the end of read buffernobu2019-03-071-0/+6
| | | | | | | * io.c (rb_io_getline_fast): chomp CR followed by LF but separated by the read buffer boundary. [ruby-core:91707] [Bug #15642] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix document and return value of `IO#autoclose=`kazu2019-02-201-4/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: remove unused variable and fix typoglass2019-02-111-3/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: check HAVE_FCOPYFILEglass2019-02-111-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: get src_size from stp. Fix r66995.glass2019-02-031-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: reuse results of fstat(2) in copy functionsglass2019-02-031-51/+26
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: use fcopyfile(3) in IO.copy_stream if availableglass2019-01-281-0/+103
| | | | | | | | | | fixed r66930. * io.c (nogvl_copy_stream_func): use fcopyfile(3) in IO.copy_stream if available * configure.ac: check copyfile.h and fcopyfile(3) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert "io.c: use fcopyfile(3) in IO.copy_stream if available"glass2019-01-271-101/+0
| | | | | | | This reverts commit bd670062c4e3a3c9fdfaaaf7bd3c232442a26a4c. It fails on rubyspec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-01-271-25/+25
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: use fcopyfile(3) in IO.copy_stream if availableglass2019-01-271-0/+102
| | | | | | | | * io.c (nogvl_copy_stream_func): use fcopyfile(3) in IO.copy_stream if available * configure.ac: check copyfile.h and fcopyfile(3) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e