Граф коммитов

304 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 cc27cd26d7 rand_range: 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
卜部昌平 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
Nobuyoshi Nakada 41e547e60c
Fixed constant initializer
An expression using `static const` value seems not considered as
`static const` by Visual C.
2020-05-04 00:27:14 +09:00
Nobuyoshi Nakada 5b28f01d77
Make int-pair-to-real conversion more portable
And utilize more bits even if DBL_MANT_DIG > 53.
2020-05-04 00:00:27 +09:00
Nobuyoshi Nakada e7128aa772
Disable deprecation error on mingw 2020-04-08 22:41:34 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 0a67c21401 Ensure seed data to be cleared
To prevent from leaking the seed data.
2020-01-10 10:28:49 +09:00
Nobuyoshi Nakada 499de0a0f6 Fill siphash salt directly with random data
Expanding less random data with MT is not needed when it
succeeded.
2020-01-10 10:28:49 +09:00
Nobuyoshi Nakada 4c5eac7323
Renamed `init_seed` as `init_hash_salt` too 2020-01-09 21:41:17 +09:00
Nobuyoshi Nakada 23fbee0311
Renamed `seed` as `hash_salt`
The role of this is a so-called "salt" but not "seed", rename to
get rid of confusion with other "seed" of PRNG.
2020-01-09 17:26:29 +09:00
Nobuyoshi Nakada 97485302db
Also clear MT to initialize the siphash seed 2020-01-09 16:00:04 +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
卜部昌平 0958e19ffb add several __has_something macro
With these macros implemented we can write codes just like we can assume
the compiler being clang.  MSC_VERSION_SINCE is defined to implement
those macros, but turned out to be handy for other places.  The -fdeclspec
compiler flag is necessary for clang to properly handle __has_declspec().
2019-12-26 20:45:12 +09:00
Kazuhiro NISHIYAMA e2b192f7d5
rand(beginless_range) raise Errno::EDOM instead of TypeError
same as `rand(endless_range)`

Before:
```
$ ruby -e 'rand(..1)'
Traceback (most recent call last):
	2: from -e:1:in `<main>'
	1: from -e:1:in `rand'
-e:1:in `-': nil can't be coerced into Integer (TypeError)
```

After:
```
$ ruby -e 'rand(..1)'
Traceback (most recent call last):
	1: from -e:1:in `<main>'
-e:1:in `rand': Numerical argument out of domain (Errno::EDOM)
```
2019-12-15 14:47:36 +09:00
Nobuyoshi Nakada 0c6f36668a
Adjusted spaces [ci skip] 2019-09-27 10:20:56 +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
git 2e2cd8297b * expand tabs. 2019-06-04 19:55:04 +09:00
Nobuyoshi Nakada 2c60f37143
random_mt_type
* random.c: renamed random_data_type as random_mt_type, and append
  "MT" to `wrap_struct_name`, respecting the implementation.
2019-06-04 19:50:41 +09:00
nobu c84a25e148 random.c: unify syscall with getrandom
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-10 10:42:50 +00:00
svn 61ffc7a0ae * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-10 08:21:39 +00:00
glass 1a8583de72 random.c: use getrandom() if available.
getrandom() is supported by glibc 2.25 or later.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-10 08:21:33 +00:00
nobu 18365f9e83 Split mt19937.c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07 08:53:12 +00:00
nobu b2a7a289e0 Fix Random.urandom in a chroot on OpenBSD
[ruby-core:90850] [Bug #15494]

From: jeremyevans0 (Jeremy Evans) <merch-redmine@jeremyevans.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 11:42:24 +00:00
shyouhei 7f6691ae77 suppress integer overflow warnings
* random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h
  overflows and that seems intentional)
* bignum.c: avoid (size_t)--
* cont.c: ditto
* util.c: ditto
* vm_insnhelper.c: ditto



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13 00:40:52 +00:00
shyouhei 234ffbce0e blacklist UBSAN's unsigned integer overflow
Integer overflow for unsigned types are fully defined in C. They
are not always problematic (but not always OK).  These functions
in this changeset intentionally utilizes that behaviour.
Blacklist from UBSAN checks for better output.

See also: https://travis-ci.org/ruby/ruby/jobs/451624829


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07 04:09:05 +00:00
svn fae6c6bfd8 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 03:22:09 +00:00
ko1 54726befc3 use RARRAY_AREF() instead of RARRAY_CONST_PTR().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 03:21:56 +00:00
nobu 6f7fafbf00 random.c: prefixed fill_random_bytes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 11:05:20 +00:00
shyouhei c2bfb4e93c add new instruction attribute called leaf
An instruction is leaf if it has no rb_funcall inside.  In order to
check this property, we introduce stack canary which is a random
number collected at runtime.  Stack top is always filled with this
number and checked for stack smashing operations, when VM_CHECK_MODE.
[GH-1947]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-11 09:48:58 +00:00
nobu 5e4627c282 random.c: fix up r64596
* random.c (fill_random_bytes_syscall): check if the version macro is
  defined, for very old Mac OS X development tools.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-04 23:10:17 +00:00
shyouhei b120f5e38d avoid fork-unsafe arc4random implementations
Some old implementaions of arc4random_buf(3) were ARC4 based, or
unsafe when forked, or both.  Resort to /dev/urandom for those
known problematic cases.  Fix [Bug #15039]

Patch from Thomas Hurst <tom@hur.st>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-04 01:42:37 +00:00
nobu 68f9d7b444 random.c: SecRandomCopyBytes
* random.c (fill_random_bytes_syscall): use SecRandomCopyBytes in
  Security framework on macOS 10.7 or later.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-31 09:56:24 +00:00
nobu a354992688 random.c: fix fallback value
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 11:13:15 +00:00
nobu 1f71ea2fd2 random.c: use rb_check_funcall
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 07:24:33 +00:00
nobu 4b4d364e52 random.c: moved domain error
* random.c (rand_range): moved call of domain_error(), not to
  raise an exception in range_values().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 07:17:20 +00:00
nobu 64712906b0 random.c: endless range random
* random.c (range_values): cannot determine the domain of an endless
  range.  [ruby-core:88261] [Bug #14958]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 06:31:22 +00:00
nobu a03ea378e7 prefer clock_gettime
* configure.ac: clock_gettime or gettimeofday must exist.

* process.c (rb_clock_gettime): prefer clock_gettime over
  gettimeofday, as the latter is obsolete in SUSv4.

* random.c (fill_random_seed): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-14 13:10:25 +00:00
nobu 8389f8c3c3 random.c: fix need_secure flags
* random.c (fill_random_seed): do not need to be secure, to get
  rid of blocking at the start-up time.
  [ruby-core:87462] [Bug #14837]

* random.c (random_raw_seed): expected to be a cryptographically
  secure, as documented.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-10 06:33:15 +00:00
stomar 5c5b64c60b random.c: improve docs for Random.bytes
* random.c: [DOC] improve language and RDoc markup in Random.bytes docs;
  also adjust call-seq style of Random.bytes and Random#bytes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-14 16:45:46 +00:00
nobu 2af1761466 random.c: Random.extend Formatter
* random.c (InitVM_Random): extend Random itself by Formatter
  module, as well as the `bytes` method used by the module.
  [Feature #4938]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-27 13:28:31 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu 1cd9c3ce62 random.c: Random.bytes
* random.c (random_s_bytes): new method Random.bytes, which is
  equivalent to Random::DEFAULT.bytes.  [Feature #4938]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-20 09:26:38 +00:00
hsbt 9869ec7a7d Fix typos.
* node.c: strucutre -> structure
 * random.c: acquried -> acquired
 * thread.c: accross -> across

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17 13:15:13 +00:00
mame 0c2f92daad random.c: make sure that Random.urandom returns required-length buffer
getrandom(2) and read(2) (from /dev/urandom) may return a random buffer
whose length is shorter than required.  This change makes sure that they
get enough buffer by using a loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-16 00:39:34 +00:00
kazu 51de1548f4 Random.urandom raises RuntimeError instead of returning nil
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-13 12:46:13 +00:00
mame d212f11a00 Random.urandom raises an exception instead of returning nil when failed
Early failure looks better in this case.  Refs [Bugs #13885].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12 13:57:36 +00:00
mame 7451ec065c Add a note to Random.urandom
The method may return nil for some reasons.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-09 15:19:19 +00:00
nobu a14cb8ad5b random.c: ensure initialized
* random.c (get_rnd, try_get_rnd): ensure initialized to get rid
  of crash in forked processes.  [ruby-core:82100] [Bug #13753]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-19 03:16:58 +00:00
shyouhei abae70d6ed SecureRandom should try /dev/urandom first [Bug #9569]
* random.c (InitVM_Random): rename Random.raw_seed to
	  Random.urandom.  A quick search seems there are no practical use
	  of this method than securerandom.rb so I think it's OK to rename
	  but if there are users of it, this hunk is subject to revert.

	* test/ruby/test_rand.rb (TestRand#test_urandom): test for it.

	* lib/securerandom.rb (SecureRandom.gen_random): Prefer OS-
	  provided CSPRNG if available. Otherwise falls back to OpenSSL.
	  Current preference is:

	  1. CSPRNG routine that the OS has; one of
	     - getrandom(2),
	     - arc4random(3), or
	     - CryptGenRandom()
	  2. /dev/urandom device
	  3. OpenSSL's RAND_bytes(3)

	  If none of above random number generators are available, you
	  cannot use this module.  An exception is raised that case.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-20 08:00:00 +00:00