906 Commits

Author SHA1 Message Date
xtkoba
c5ff954410 Get rid of unused function warning for _WIN32 2021-10-03 11:06:24 +09:00
Nobuyoshi Nakada
3e46117d3f Associate the encoding to the found path 2021-10-01 20:28:44 +09:00
S.H
b8c3a84bdd
Refactor and Using RBOOL macro 2021-09-15 08:11:05 +09:00
S-H-GAMELINKS
bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
S-H-GAMELINKS
4794a8a7cf Add stat_time function 2021-08-24 09:23:07 +09:00
Akinori MUSHA
4814528296 [DOC] Fix the rdoc for File::Stat#size? [ci skip] 2021-08-17 21:44:41 +09:00
S.H
378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
S.H
64adeeadaa
Add RBOOL macro and use it 2021-07-29 12:51:10 +09:00
Burdette Lamar
c1741df1a1 What's Here for Numeric and Comparable 2021-06-21 10:38:16 -07:00
Burdette Lamar
4337da377e
What's Here for class File (#4460)
What's Here for class File
2021-05-07 11:22:32 -05:00
Nobuyoshi Nakada
a5688b5ce6
Support non-standard struct stat [Bug #17793]
On 32-bit Android:
* `st_dev`/`st_rdev` are not `dev_t`
* `st_mode` is not `mode_t`
2021-04-12 15:32:49 +09:00
Nobuyoshi Nakada
43e0677c6d Fill the ring-buffer with the fallback value
Fill with the pointer to the root position, instead of zero and
comparing later.  Also suppress a false warning by Visual C++.

```
file.c(4759): warning C4090: 'function': different 'const' qualifiers
```
2021-04-02 14:17:33 +09:00
Nobuyoshi Nakada
82b6f89283 File.dirname optional level
* file.c (rb_file_dirname_n): chomp N level of base names.
  [Feature #12194]
2021-03-15 15:09:05 +09:00
xtkoba (Tee KOBAYASHI)
3ac28de541
Explicitly cast __s64 to time_t [Bug #17645]
A workaround of shorten-64-to-32 error where 32-bit linux.
2021-03-14 20:10:01 +09:00
Nobuyoshi Nakada
0d57d59933 Keep encoding in the result of File.expand_path [Bug #17517] 2021-01-15 17:46:48 +09:00
Nobuyoshi Nakada
4e01ab342a
Revert "Removed deprecated Dir.exists? and File.exists?"
This reverts commit 1a5205536f0c0d6021450b11722919211847df86.
2020-12-02 19:11:01 +09:00
Nobuyoshi Nakada
1a5205536f
Removed deprecated Dir.exists? and File.exists? 2020-12-02 17:24:34 +09:00
Hiroshi SHIBATA
e380f78851 Removed rb_find_file_ext_safe and rb_find_file_safe 2020-09-23 09:09:36 +09:00
Jean Boussier
2c6512fe67 Get rid of the redundant stat() in rb_check_realpath_internal 2020-07-07 00:26:37 +09:00
卜部昌平
de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平
e9cb092b2d rb_f_stat: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada
c3ba2db48b
Removed execpath argument of path_check_0 as always TRUE now 2020-06-23 10:01:23 +09:00
Nobuyoshi Nakada
61374839e4
Removed fpath_check, no longer used since taint flag was removed 2020-06-23 10:01:23 +09:00
Alan D. Salewski
c15cddd1d5 Allow Dir.home to work for non-login procs when $HOME not set
Allow the 'Dir.home' method to reliably locate the user's home directory when
all three of the following are true at the same time:

    1. Ruby is running on a Unix-like OS
    2. The $HOME environment variable is not set
    3. The process is not a descendant of login(1) (or a work-alike)

The prior behavior was that the lookup could only work for login-descended
processes.

This is accomplished by looking up the user's record in the password database
by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3))
which is still attempted first (based on the name, if any, returned by
getlogin_r(3)).

If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at
compile time, will fallback on using their respective non-*_r() variants:
getlogin(3), getpwnam(3), and/or getpwuid(3).

The rationale for attempting to do the lookup by name prior to doing it by uid
is to accommodate the possibility of multiple login names (each with its own
record in the password database, so each with a potentially different home
directory) being mapped to the same uid (as is explicitly allowed for by
POSIX; see getlogin(3posix)).

Preserves the existing behavior for login-descended processes, and adds the
new capability of having Dir.home being able to find the user's home directory
for non-login-descended processes.

Fixes [Bug #16787]

Related discussion:
    https://bugs.ruby-lang.org/issues/16787
    https://github.com/ruby/ruby/pull/3034
2020-05-23 23:16:28 +09:00
卜部昌平
9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平
d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平
9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada
67f616c523
Show the deprecated name in the warning
Fixed up a58bbd6a512d95ca010d8bebae4fe590400c1413.
2020-04-07 12:49:33 +09:00
Nobuyoshi Nakada
d827c718db
[DOC] Removed RDoc of deprecated methods [ci skip] 2020-04-06 23:06:03 +09:00
Nobuyoshi Nakada
a58bbd6a51
Use rb_warn_deprecated for File.exists? and Dir.exists? 2020-04-06 21:43:32 +09:00
卜部昌平
5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
NAKAMURA Usaku
204dc3f39f Revert "Should return "." for File.extname("file.") also on Windows"
We want to introduce consistency and better compatibility with unixen,
but the Windows APIs doues not have consistency fundamentally and
we can not found any logical way...

This reverts commit 61aff0cd189e67fa6f2565639ad0128fa33b88fc.
2019-12-23 11:54:25 +09:00
NAKAMURA Usaku
61aff0cd18 Should return "." for File.extname("file.") also on Windows
But not changes another cases, such as "file.rb."
[Bug #15267]
2019-12-22 02:42:09 +09:00
Nobuyoshi Nakada
04e95f8985 Get rid of infinite recursion at loading transcoder
Disable encoding US-ASCII path to filesystem on Windows too.
[Bug #16392]
2019-12-16 16:16:54 +09:00
Nobuyoshi Nakada
14a17063a1
Fixed stack overflow [Bug #16382]
Get rid of infinite recursion in expanding a load path to the real
path while loading a transcoder.
2019-12-03 08:51:50 +09:00
Jeremy Evans
ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Jeremy Evans
c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
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.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada
4f13927f1f
[DOC] no change on Windows [Bug #15267] [ci skip] 2019-10-17 19:43:10 +09:00
Nobuyoshi Nakada
e169ad93f4 Fixed File.extname at a name ending with a dot
File.extname now returns a dot string at a name ending with a dot.
[Bug #15267]
2019-10-17 18:51:51 +09:00
Jeremy Evans
978276a7d9 Update documentation for File#{readable,writable,executable}{,_real}? [ci skip]
Some OS-level security features cause these methods to not return
expected results.  For example fs.protected_regular sysctl on Linux,
or pledge(2)/unveil(2) on OpenBSD.

Fixes [Bug #16002]
2019-10-14 17:43:11 -07:00
Nobuyoshi Nakada
0c6f36668a
Adjusted spaces [ci skip] 2019-09-27 10:20:56 +09:00
David Rodríguez
2a166cfea2 Add File.absolute_path? (#2198)
In order to check whether a path is absolute or not in a portable way.

[Feature #15868]
2019-09-05 20:00:50 +09:00
卜部昌平
3df37259d8 drop-in type check for rb_define_singleton_method
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.
2019-08-29 18:34:09 +09:00
卜部昌平
7bcfd9189a drop-in type check for rb_define_global_function
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.
2019-08-29 18:34:09 +09:00
Jeremy Evans
a50bc9f3c8 Do not always taint the result of File#path
The result should only be tainted if the path given to the method
was tainted.

The code to always taint the result was added in
a4934a42cbb84b6679912226581c71b435671f55 (svn revision 4892) in
2003 by matz.  However, the change wasn't mentioned in the
commit message, and it may have been committed by accident.

Skip part of a readline test that uses Reline.  Reline in general
would pass the test, but Reline's test mode doesn't raise a
SecurityError if passing a tainted prompt and $SAFE >= 1. This
was hidden earlier because File#path was always returning a
tainted string.

Fixes [Bug #14485]
2019-07-30 11:55:59 -07:00
Jeremy Evans
6eab49a40a Revert "Do not always taint the result of File#path"
This reverts commit 1a759bfe5d554c22571d2e6e4e5998cf06a7b98f.

This fails on some operating systems.
2019-07-29 12:10:15 -07:00
Jeremy Evans
1a759bfe5d Do not always taint the result of File#path
The result should only be tainted if the path given to the method
was tainted.

The code to always taint the result was added in
a4934a42cbb84b6679912226581c71b435671f55 (svn revision 4892) in
2003 by matz.  However, the change wasn't mentioned in the
commit message, and it may have been committed by accident.

Skip part of a readline test that uses Reline.  Reline in general
would pass the test, but Reline's test mode doesn't raise a
SecurityError if passing a tainted prompt and $SAFE >= 1. This
was hidden earlier because File#path was always returning a
tainted string.

Fixes [Bug #14485]
2019-07-29 10:45:14 -07:00
Yusuke Endoh
81fc3becc7 file.c: add a NORETURN declaration for statx_notimplement
clang complains the lack.
2019-07-20 15:43:42 +09:00
git
9987296b8b * expand tabs. 2019-07-14 17:16:35 +09:00
Yusuke Endoh
934e6b2aeb Prefer rb_error_arity to rb_check_arity when it can be used 2019-07-14 17:16:19 +09:00