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

281 Коммитов

Автор SHA1 Сообщение Дата
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
shyouhei 04c94f95d1 switch SipHash from SipHash24 to SipHash13 variant
SipHash13 is secure enough to be used in hash-tables,
and SipHash's author confirms that.
Rust already considered switch to SipHash13:
  https://github.com/rust-lang/rust/issues/29754#issue-116174313
Jean-Philippe Aumasson confirmation:
  https://github.com/rust-lang/rust/issues/29754#issuecomment-156073946
Merged pull request:
  https://github.com/rust-lang/rust/pull/33940

From: Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>
Date: Thu, 8 Dec 2016 20:31:29 +0300
Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>
Fixes: [Feature #13017]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-20 06:01:23 +00:00
normal 208018fb9d random.c (fill_random_bytes_syscall): use "__NR_" prefix on Linux
glibc still does not define the SYS_getrandom alias for
__NR_getrandom in the Linux kernel.  However, installing
up-to-date Linux kernel headers (linux-libc-dev >= 3.17 package
on Debian) will get the __NR_getrandom syscall number defined
properly without relying on glibc.

This allows users with a modern kernel+headers to use the getrandom
syscall without waiting on glibc support.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-11 22:38:50 +00:00
nobu 1816e39351 random.c: pack hash seeds
* random.c (seed_keys_t, init_seed): pack seed for rb_hash_start and
  rb_memhash, and fill them at once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 03:25:21 +00:00
nobu 74ba0cfc62 random.c: private rand
* random.c (rb_random_ulong_limited): do not call private method
  rand.  [ruby-dev:49892] [Misc #13003]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-05 00:03:45 +00:00
nobu c463366dfd rb_funcallv
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions
  which are/will be/may be gems.  [Fix GH-1406]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-29 11:57:14 +00:00
naruse 454f028632 * random.c (random_ulong_limited): avoid left shift count >= width of
type on 32bit environment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-04 04:09:51 +00:00
nobu 91ec3d8fbe VC6 error
* random.c (int_pair_to_real_inclusive): get rid of VC6 compile
  error C2520: conversion from unsigned __int64 to double not
  implemented.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-29 04:37:13 +00:00
nobu 9529e46adf random.c: suppress a warning
* random.c (random_ulong_limited): suppress a shift count warning
  when unsigned long is 32bits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-15 03:03:45 +00:00
nobu 6d4fb98e59 random.c: clear seed
* random.c (rand_init): clear packed seed value explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-14 23:21:31 +00:00
nobu d009cebf0f random.c: no local copy of the seed
* random.c (make_seed_value): append leading-zero-guard and get
  rid of making a local copy of the seed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 15:16:57 +00:00
nobu 79850a0829 random.c: fill_random_seed size
* random.c (fill_random_seed): move the seed size to an argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 15:16:56 +00:00
nobu 678c39dc44 random.c: clear buf
* random.c (random_seed): clear temporary buffer explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-13 14:56:32 +00:00
nobu 15fbd05e4e random.c: reuse bits
* random.c (random_ulong_limited): reduce calling bytes methods by
  reusing dropped bits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-10 06:46:09 +00:00
nobu b402cc7161 random.c: use bytes
* random.c (obj_random_bytes): base on bytes method instead of
  rand method, not to call toplevel rand method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-10 05:57:11 +00:00
nobu a6b221f238 random.c: compare by rb_equal
* random.c (random_equal): compare seeds by rb_equal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 16:25:53 +00:00
nobu 8610bd032a random.c: consitify
* random.c (init_by_array): consitify initializing keys.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 04:27:12 +00:00
nobu ad949e8f31 random.c: seed conversion
* random.c (rand_init): random_seed() always returns an Integer,
  no conversion for it.

* random.c (random_init, rb_f_srand): convert the given seed to an
  Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 03:52:09 +00:00
nobu ed5b985650 random.c: optimize int_pair_to_real_inclusive
* random.c (int_pair_to_real_inclusive): optimize to multiply
  without Bignum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 07:22:14 +00:00
nobu 091d88ab4b random.c: split random_int32
* random.c (random_int32): split the cases of rb_random_t and
  other objects.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 06:21:00 +00:00
nobu 1a696e35c8 random.c: unnecessary declarations
* random.c (random_ulong_limited, random_ulong_limited_big):
  remove unnecessary extern declarations.  rb_num_negative_p is
  declared in internal.h now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-07 02:59:32 +00:00
nobu c0f920093e random.c: fill_random_bytes_syscall function
* random.c (fill_random_bytes_syscall): turned into a static
  function, to be inlined probably, so that it is unavailable if
  it is a preprocessor macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 07:18:34 +00:00
nobu a331eeb529 random.c: refactor
* random.c (rand_random, rb_f_rand): refactor, split condition
  expressions, and return in the precedence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 07:18:33 +00:00
nobu 3377db6b32 random.c: use rb_check_to_int
* random.c (rand_range, rand_random): use rb_check_to_int instead
  of rb_check_to_integer with the same conversion method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 06:52:37 +00:00