Commit graph

20692 commits

Author SHA1 Message Date
Jeremy Evans
55720f372d [ruby/openssl] pkcs7: raise PKCS7Error for PKCS7 without content in PKCS7.read_smime
[pkuzco: expanded the fix for other content types]
[ky: adjusted formatting and the exception type]

07eceb7f63

Co-authored-by: pkuzco <b.naamneh@gmail.com>
Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
2024-05-02 16:26:11 +09:00
Jeremy Evans
c9aa63a9e0 [ruby/openssl] pkcs7: raise ArgumentError for PKCS7 with no content in PKCS7.new
Fixes [Bug #19974]

[pkuzco: expanded the fix for other content types]
[ky: adjusted formatting and the exception type]

27e11f2d1d

Co-authored-by: pkuzco <b.naamneh@gmail.com>
Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
2024-05-02 16:26:11 +09:00
Kazuki Yamaguchi
eb6f0000a4 [ruby/openssl] cipher: fix buffer overflow in Cipher#update
OpenSSL::Cipher#update currently allocates the output buffer with size
(input data length)+(the block size of the cipher). This is insufficient
for the id-aes{128,192,256}-wrap-pad (AES keywrap with padding) ciphers.
They have a block size of 8 bytes, but the output may be up to 15 bytes
larger than the input.

Use (input data length)+EVP_MAX_BLOCK_LENGTH (== 32) as the output
buffer size, instead. OpenSSL doesn't provide a generic way to tell the
maximum required buffer size for ciphers, but this is large enough for
all algorithms implemented in current versions of OpenSSL.

Fixes: https://bugs.ruby-lang.org/issues/20236

3035559f54
2024-05-02 16:26:11 +09:00
tomoya ishida
eb82ea6218 [ruby/reline] Fix prompt width calculation bug. Test with colored
prompt
(https://github.com/ruby/reline/pull/695)

24aab01cbc
2024-05-02 06:06:31 +00:00
Kevin Newton
f109a83ddf [PRISM] Fix up error message expectations 2024-05-01 19:19:07 -04:00
Kevin Newton
ac0f6716b1 [PRISM] Respect frozen_string_literal option in RubyVM::InstructionSequence.compile 2024-05-01 19:19:07 -04:00
Kevin Newton
8ea6daa86d [PRISM] Enable passing tests in test_syntax.rb 2024-05-01 19:19:07 -04:00
Kevin Newton
1be5ede766 [PRISM] Error message for unterminated heredoc identifier 2024-05-01 19:19:07 -04:00
Kevin Newton
62f8fb7f89 [PRISM] Fix unterminated regular expression error message 2024-05-01 19:19:07 -04:00
Kevin Newton
5d1e4cd249 [PRISM] Better error messages for unwriteable targets 2024-05-01 19:19:07 -04:00
Kevin Newton
8e1647c3aa [ruby/prism] Support passing version 3.3.1
445a0f0d22
2024-05-01 23:03:25 +00:00
Kevin Newton
5cd0abdfb5 [PRISM] Simplify prism error highlighting 2024-05-01 16:57:29 -04:00
Kevin Newton
fc8fb581cf [ruby/prism] CRuby error message for trailing underscore in number
4e34f236d3
2024-05-01 19:51:09 +00:00
Kevin Newton
41f8ae1ffd [ruby/prism] Mark errors for invalid symbols
661884c4a3
2024-05-01 16:43:05 +00:00
Kevin Newton
cfe7019ef5 [ruby/prism] Match CRuby interpolation semantics
If a single string that is a static literal is interpolated, it
does not impact whether or not the parent is a static literal. In
this way, if you have something like a regular expression that
interpolates a string literal, it's possible that you will end up
pushing just a single regexp onto the stack as opposed to calling
out to toregexp.

4f096c2257
2024-05-01 12:34:29 -04:00
Kevin Newton
b6fa18fbe9 [PRISM] Properly precheck regexp for encoding issues 2024-05-01 12:34:29 -04:00
Kevin Newton
1b8650964b [PRISM] Support interpolated regexp with encoding modifiers 2024-05-01 12:34:29 -04:00
Peter Zhu
7ef8bb129f Fix memory leak in Ripper.sexp
rb_ast_dispose does not free the rb_ast_t causing it to be leaked. This
commit changes it to use rb_ast_free instead.

For example:

    require "ripper"

    10.times do
      100_000.times do
        Ripper.sexp("")
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    27648
    32512
    37376
    42240
    47232
    52224
    57344
    62208
    67072
    71936

After:

    22784
    22784
    22784
    22784
    22912
    22912
    22912
    22912
    22912
    22912
2024-05-01 11:09:54 -04:00
Stan Lo
1000c27db8 [ruby/irb] Support IRB.conf[:BACKTRACE_FILTER]
(https://github.com/ruby/irb/pull/917)

* Use 'irbtest-' instead if 'irb-' as prefix of test files.

Otherwise IRB would mis-recognize exceptions raised in test files as
exceptions raised in IRB itself.

* Support `IRB.conf[:BACKTRACE_FILTER]``

This config allows users to customize the backtrace of exceptions raised
and displayed in IRB sessions. This is useful for filtering out library
frames from the backtrace.

IRB expects the given value to response to `call` method and return
the filtered backtrace.

6f6e87d769
2024-05-01 14:23:09 +00:00
Nobuyoshi Nakada
57eca0a80d
Test for memory leak 2024-05-01 17:46:41 +09:00
Sutou Kouhei
0c13596686 [ruby/delegate] test: remove needless mu_pp
It's for minitest. We don't need it with test-unit.

447cd43973
2024-04-30 23:31:26 +00:00
tomoya ishida
614187f8c2 [ruby/reline] Fix completion dialog position when completed part is
wordwrapped
(https://github.com/ruby/reline/pull/692)

2d9acd16fe
2024-04-30 16:51:25 +00:00
Peter Zhu
e0949c3f7c [ruby/openssl] Remove trailing space in test_ssl.rb
911a31335f
2024-04-30 15:23:15 +00:00
Bart de Water
cc6657e563 [ruby/openssl] Add OpenSSL::Digest.digests to get a list of available digests
08dd3c73b7
2024-04-30 15:05:50 +00:00
Samuel Williams
1699772ac4 [ruby/openssl] Introduce basic support for close_read and close_write.
c99d24cee9
2024-04-30 14:51:58 +00:00
tomoya ishida
8fb430c1da [ruby/irb] Restore MAIN_CONTEXT correctly
(https://github.com/ruby/irb/pull/937)

c41f460a70
2024-04-30 10:29:38 +00:00
tomoya ishida
814d4b5e2c [ruby/reline] Input with eof and no newline bugfix
(https://github.com/ruby/reline/pull/671)

0d66c335a1
2024-04-29 13:23:03 +00:00
tomoya ishida
ae701031f5 [ruby/reline] Completely support full-width characters in
differential rendering
(https://github.com/ruby/reline/pull/654)

* Add a cut variation of Reline::Unicode.take_range method take_mbchar_range

* Consider fullwidth take_range in differential rendering

29714df09f
2024-04-29 12:08:59 +00:00
Mari Imaizumi
018c5717e5 [ruby/reline] Handle mode condition in inputrc
(https://github.com/ruby/reline/pull/687)

bed5fb3d77
2024-04-29 12:05:36 +00:00
Kevin Newton
ddce8ca831 [PRISM] Enable integer test 2024-04-26 17:01:13 -04:00
Kevin Newton
46480e3042 [PRISM] Use redundant return flag 2024-04-26 15:16:58 -04:00
Kevin Newton
9688093124 [ruby/prism] Location#slice_lines, Node#slice_lines
9b61f6fdb3
2024-04-26 19:05:32 +00:00
Kevin Newton
6a296089c6 [ruby/prism] Add a flag on returns when they are redundant
450541d2c3
2024-04-26 18:10:42 +00:00
Stan Lo
148518baa0 [ruby/irb] Suppress command return values
(https://github.com/ruby/irb/pull/934)

Since commands can't be chained with methods, their return values are
not intended to be used. But if IRB keeps storing command return values
as the last value, and print them, users may rely on such implicit
behaviour.

So to avoid such confusion, this commit suppresses command's
return values. It also updates some commands that currently rely on
this implicit behaviour.

fa96bea76f
2024-04-26 17:52:12 +00:00
Job Snijders
6b120135af [ruby/openssl] Only CSR version 1 (encoded as 0) is allowed by PKIX standards
RFC 2986, section 4.1 only defines version 1 for CSRs. This version
is encoded as a 0. Starting with OpenSSL 3.3, setting the CSR version
to anything but 1 fails.

Do not attempt to generate a CSR with invalid version (which now fails)
and invalidate the CSR in test_sign_and_verify_rsa_sha1 by changing its
subject rather than using an invalid version.

This commit fixes the following error.

```
 2) Error: test_version(OpenSSL::TestX509Request): OpenSSL::X509::RequestError:
X509_REQ_set_version: passed invalid argument
/home/runner/work/openssl/openssl/test/openssl/test_x509req.rb:18:in `version='
/home/runner/work/openssl/openssl/test/openssl/test_x509req.rb:18:in `issue_csr'
/home/runner/work/openssl/openssl/test/openssl/test_x509req.rb:43:in
`test_version'
     40:     req = OpenSSL::X509::Request.new(req.to_der)
     41:     assert_equal(0, req.version)
     42:
  => 43:     req = issue_csr(1, @dn, @rsa1024, OpenSSL::Digest.new('SHA256'))
     44:     assert_equal(1, req.version)
     45:     req = OpenSSL::X509::Request.new(req.to_der)
     46:     assert_equal(1, req.version)
```

c06fdeb091
2024-04-26 16:55:15 +00:00
Kevin Newton
9aecff2530 [PRISM] Fix up if condition branch coverage location 2024-04-26 12:25:45 -04:00
Kevin Newton
c46e32e342 [PRISM] Fix up branch coverage for &. with block 2024-04-26 12:25:45 -04:00
Kevin Newton
d06bbafd3f [PRISM] Enable branch coverage for if/unless conditionals 2024-04-26 12:25:45 -04:00
Kevin Newton
881c450135 [PRISM] Enable branch coverage for while/until loops 2024-04-26 12:25:45 -04:00
Kevin Newton
43076bf9d1 [PRISM] Enable branch coverage for case pattern matching 2024-04-26 12:25:45 -04:00
Kevin Newton
e5bd4c78b2 [PRISM] Enable branch coverage for case 2024-04-26 12:25:45 -04:00
Kevin Newton
235a3f3b7c [PRISM] Enable branch coverage for &. 2024-04-26 12:25:45 -04:00
Kevin Newton
6509634eba [PRISM] Modify test_coverage to take prism into account 2024-04-26 12:25:45 -04:00
Stan Lo
25a8b76c76 [ruby/irb] Command registration should take both strings and symbols
as names
(https://github.com/ruby/irb/pull/932)

This will save users some heads scratching when they try to register a
command with a string name and found that it doesn't work.

I also rewrote converted custom command tests into integration tests to
make test setup/cleanup easier.

a91a212dbe
2024-04-26 12:12:31 +00:00
tomoya ishida
4ff249363d [ruby/reline] Fix inputrc nested $if $else $endif bug
(https://github.com/ruby/reline/pull/689)

0d8aea26ec
2024-04-25 16:12:50 +00:00
Daniel Colson
3a5d9553a7 Don't use assert_separately in Bug 20453 test
https://github.com/ruby/ruby/pull/10630#discussion_r1579565056

The PR was merged before I had a chance to address this feedback.
`assert_separately` is not necessary for this test if I don't use a
global timeout.
2024-04-25 11:28:56 -04:00
Daniel Colson
d292a9b98c [Bug #20453] segfault in Regexp timeout
https://bugs.ruby-lang.org/issues/20228 started freeing `stk_base` to
avoid a memory leak. But `stk_base` is sometimes stack allocated (using
`xalloca`), so the free only works if the regex stack has grown enough
to hit `stack_double` (which uses `xmalloc` and `xrealloc`).

To reproduce the problem on master and 3.3.1:

```ruby
Regexp.timeout = 0.001
/^(a*)x$/ =~ "a" * 1000000 + "x"'
```

Some details about this potential fix:

`stk_base == stk_alloc` on
[init](dde99215f2/regexec.c (L1153)),
so if `stk_base != stk_alloc` we can be sure we called
[`stack_double`](dde99215f2/regexec.c (L1210))
and it's safe to free. It's also safe to free if we've
[saved](dde99215f2/regexec.c (L1187-L1189))
the stack to `msa->stack_p`, since we do the `stk_base != stk_alloc`
check before saving.

This matches the check we do inside
[`stack_double`](dde99215f2/regexec.c (L1221))
2024-04-25 10:28:18 -04:00
Kevin Newton
b50e1e68b6 [PRISM] Enable more passing tests 2024-04-25 08:14:56 -04:00
Xi Ruoyao
03f8477566 [ruby/net-http] Skip test_session_reuse_but_expire with OpenSSL 3.3
OpenSSL 3.3.0 9 Apr 2024 is also broken.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>

ab525c956d
2024-04-25 08:01:53 +00:00
Kevin Newton
4c431744b7 [ruby/prism] Warn for nested hashes as well
76e802f59e
2024-04-24 19:39:42 +00:00