Commit graph

9970 commits

Author SHA1 Message Date
Jeremy Drake
c9346a166c [ruby/resolv] win32/resolv: add headers to GetNetworkParams check.
On 32-bit Cygwin at least, it was failing to find that function,
presumably due to it being stdcall.

Signed-off-by: Jeremy Drake <github@jdrake.com>

bceafef74b
2025-08-13 22:13:53 +00:00
Nobuyoshi Nakada
77b3495e97 [ruby/stringio] Adjust indent [ci skip]
ac6292c17f
2025-08-09 11:16:03 +00:00
Nobuyoshi Nakada
31f2d8990d [ruby/stringio] Fix SEGV at read/pread on null StringIO
113dd5a55e
2025-08-09 11:12:48 +00:00
koh-sh
23c0113932 [ruby/stringio] fix: prevent segfault in StringIO#seek with SEEK_END
on null device
(https://github.com/ruby/stringio/pull/137)

Fixes segmentation fault when calling `seek` with `SEEK_END` on null
device StringIO created by
  `StringIO.new(nil)`.

```bash
ruby -e "require 'stringio'; StringIO.new(nil).seek(0, IO::SEEK_END)"
```

I tested with below versions.

```bash
[koh@Kohs-MacBook-Pro] ~
% ruby -v;gem info stringio;sw_vers
ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [arm64-darwin24]

*** LOCAL GEMS ***

stringio (3.1.2)
    Authors: Nobu Nakada, Charles Oliver Nutter
    Homepage: https://github.com/ruby/stringio
    Licenses: Ruby, BSD-2-Clause
    Installed at (default): /Users/koh/.local/share/mise/installs/ruby/3.4.5/lib/ruby/gems/3.4.0

    Pseudo IO on String
ProductName:            macOS
ProductVersion:         15.5
BuildVersion:           24F74
[koh@Kohs-MacBook-Pro] ~
%
```

9399747bf9
2025-08-09 09:30:27 +00:00
John Hawthorn
640a2f1dc7 Ensure ObjectSpace.dump won't call cc_cme on invalidated CC 2025-08-06 15:57:13 -07:00
Jean Boussier
1c6b36af18
Only define String.json_create & al when json/add is required
All the `json/add` related methods for string were
always defined unconditionally from the generators.

It's preferable to only define them if `json/add` is actually used.
2025-08-04 09:29:53 +09:00
Kazuki Yamaguchi
497782856a [ruby/openssl] pkcs7: make PKCS7#add_recipient actually useful
Add a simple test case that creates an enveloped-data structure without
using the shorthand method, and fix two issues preventing this from
working correctly.

First, OpenSSL::PKey::PKCS7#add_recipient currently inserts an
incomplete PKCS7_RECIP_INFO object into the PKCS7 object. When
duplicating an unfinalized PKCS7_RECIP_INFO, the internal X509 reference
must also be copied, as it is later used by #add_data to fill the rest.

A similar issue with #add_signer was fixed in commit 20ca7a27a8
(pkcs7: keep private key when duplicating PKCS7_SIGNER_INFO,
2021-03-24).

Second, #add_data calls PKCS7_dataFinal(), which for enveloped-data
appears to require the BIO to be flushed explicitly with BIO_flush().
Without this, the last block of the encrypted data would be missing.

9595ecf643
2025-08-01 12:04:06 +00:00
Kazuki Yamaguchi
046780179b [ruby/openssl] pkcs7: refactor error handling in PKCS7#add_data
Raise an exception right after an OpenSSL function returns an error.
Checking ERR_peek_error() is not reliable way to see if an error has
occurred or not, as OpenSSL functions do not always populate the error
queue.

cc3f1af73e
2025-08-01 12:04:06 +00:00
Kazuki Yamaguchi
3fe4ab0d23 [ruby/openssl] pkcs7: fix error queue leak in OpenSSL::PKCS7#detached
Only call PKCS7_get_detached() if the PKCS7 object is a signed-data.
This is only useful for the content type, and leaves an error entry if
called on a PKCS7 object with a different content type.

8997f6d5e6
2025-08-01 12:03:39 +00:00
Jean Boussier
f0c31c5e64 Get rid of RSHAPE_PARENT in favor of RSHAPE_DIRECT_CHILD_P
`RSHAPE_PARENT` is error prone because it returns a raw untagged
shape_id.

To check if a shape is a direct parent of another, tags should be
discarded. So providing a comparison function is better than exposing
untagged ids.
2025-07-31 21:55:51 +02:00
Kazuki Yamaguchi
69ff8f736b [ruby/openssl] pkcs7: only set error_string in the error path
Set the error_string attribute to nil if PKCS7_verify() succeeds, since
the error queue should be empty in that case.

With AWS-LC, OpenSSL::PKCS#verify currently sets error_string to
"invalid library (0)" when the verification succeeds, whereas with
OpenSSL and LibreSSL, it becomes nil. ERR_reason_error_string() appears
to behave differently when an invalid error code is passed.

The branch to raise OpenSSL::PKCS7::PKCS7Error is removed because it
does not appear to be reachable.

c11c6631fa
2025-07-31 17:38:35 +00:00
Kazuki Yamaguchi
0d3d296b85 Reapply "[ruby/openssl] x509: disallow ossl_x509{,attr,crl,ext,revoked,name}*_new(NULL)"
This reverts commit ec01cd9bbb.

This should no longer break the tests, now that the following changes
have been applied:

 - RubyGems change: 32977f3869
 - ruby/openssl change: e8261963c7
2025-07-31 18:45:53 +09:00
Kazuki Yamaguchi
e8261963c7 [ruby/openssl] x509store: fix StoreContext#current_cert
Commit ef277083ba overlooked a caller of ossl_x509_new() with NULL
argument. OpenSSL::X509::StoreContext#current_cert may not have a
certificate to return if StoreContext#verify has not been called.

4149b43890
2025-07-31 09:45:35 +00:00
Jean Boussier
7ee127d2d1 Get rid of imemo_ast
It has been marked as obsolete for a while and I see no reason
to keep it.
2025-07-29 13:05:12 +02:00
Nobuyoshi Nakada
d9a14c299f
Fix ext/-test-/namespace/yay{1,2} for mswin
Visual C:
```
compiling ../../../../../src/ext/-test-/namespace/yay1/yay1.c
yay1.c
../../../../../src/ext/-test-/namespace/yay1/yay1.c(4): warning C4273: 'yay_value': inconsistent dll linkage
C:\a\ruby\ruby\src\ext\-test-\namespace\yay1\yay1.h(4): note: see previous definition of 'yay_value'
linking shared-object -test-/namespace/yay1.so
   Creating library yay1-arm64-mswin64_140.lib and object yay1-arm64-mswin64_140.exp
yay1-arm64-mswin64_140.exp : warning LNK4070: /OUT:yay1.dll directive in .EXP differs from output filename '..\..\..\..\.ext\arm64-mswin64_140\-test-\namespace\yay1.so'; ignoring directive
compiling ../../../../../src/ext/-test-/namespace/yay2/yay2.c
yay2.c
../../../../../src/ext/-test-/namespace/yay2/yay2.c(4): warning C4273: 'yay_value': inconsistent dll linkage
C:\a\ruby\ruby\src\ext\-test-\namespace\yay2\yay2.h(4): note: see previous definition of 'yay_value'
linking shared-object -test-/namespace/yay2.so
   Creating library yay2-arm64-mswin64_140.lib and object yay2-arm64-mswin64_140.exp
yay2-arm64-mswin64_140.exp : warning LNK4070: /OUT:yay2.dll directive in .EXP differs from output filename '..\..\..\..\.ext\arm64-mswin64_140\-test-\namespace\yay2.so'; ignoring directive
```

From MinGW gcc:
```
../../../../../src/ext/-test-/namespace/yay1/yay1.c:4:1: warning: 'yay_value' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
    4 | yay_value(void)
      | ^~~~~~~~~
../../../../../src/ext/-test-/namespace/yay2/yay2.c:4:1: warning: 'yay_value' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
    4 | yay_value(void)
      | ^~~~~~~~~
```
2025-07-29 13:25:09 +09:00
Jean Boussier
8e426a3aee [ruby/json] Release 2.13.2
9e3efbfa22
2025-07-29 10:41:09 +09:00
Jean Boussier
48a79cd492 [ruby/json] Improve deprecation warning location detection
132049bde2
2025-07-28 09:39:12 +09:00
Jean Boussier
d0020d58f4 [ruby/json] Fix duplicated key warning location
Followup: https://github.com/ruby/json/pull/818

Now the warning should point at the `JSON.parse` caller, and not
inside the json gem itself.

cd51557387
2025-07-28 09:39:12 +09:00
Jean Boussier
b4ef5da70b [ruby/json] Improve duplicate key warning and errors to include the key name
Followup: https://github.com/ruby/json/pull/818

e3de4cc59c
2025-07-28 09:39:11 +09:00
Kazuki Yamaguchi
ec01cd9bbb Revert "[ruby/openssl] x509: disallow ossl_x509{,attr,crl,ext,revoked,name}*_new(NULL)"
This reverts commit 4e8bbb07dd.

It broke RubyGems tests:
20250727T123003Z.fail.html.gz

OpenSSL::X509::StoreContext#current_cert incorrectly calls
ossl_x509_new() with NULL to create a bogus Certificate object, and a
test case in RubyGems relies on it. This will be reapplied when both
are fixed.
2025-07-27 22:56:10 +09:00
Kazuki Yamaguchi
1c18ab81db [ruby/openssl] pkey: rename ossl_pkey_new() to ossl_pkey_wrap()
Among functions named ossl_*_new(), ossl_pkey_new() is now the only one
that takes ownership of the passed OpenSSL object instead of making a
copy or incrementing its reference counter. Rename it to make this
behavior easier to understand.

54c1c26eb5
2025-07-27 12:17:25 +00:00
Kazuki Yamaguchi
f85dafebe8 [ruby/openssl] ocsp: refactor ossl_ocspcertid_new()
Likewise, let it take a const pointer and not the ownership of the
OpenSSL object.

This fixes potential memory leak in OpenSSL::OCSP::BasicResponse#status.

7e0288ebbd
2025-07-27 12:17:25 +00:00
Kazuki Yamaguchi
5a04353417 [ruby/openssl] ocsp: refactor ossl_ocspsres_new()
Similar to most of the other ossl_*_new() functions, let it take a const
pointer and make a copy of the object.

This also fixes a potential memory leak when the wrapper object
allocation fails.

eaabf6d8a3
2025-07-27 12:17:24 +00:00
Kazuki Yamaguchi
e80c3f3ba9 [ruby/openssl] pkcs7: disallow ossl_pkcs7{si,ri}_new(NULL)
These functions are not actually called with NULL.

c089301e56
2025-07-27 12:17:24 +00:00
Kazuki Yamaguchi
4e8bbb07dd [ruby/openssl] x509: disallow ossl_x509{,attr,crl,ext,revoked,name}*_new(NULL)
These functions are not actually called with NULL. It also doesn't make
sense to do so, so let's simplify the definitions.

ef277083ba
2025-07-27 12:17:24 +00:00
Kazuki Yamaguchi
ba0b3ad4f3 [ruby/openssl] bn: avoid ossl_bn_new(NULL)
Currently, calling ossl_bn_new() with a NULL argument allocates a new
OpenSSL::BN instance representing 0. This behavior is confusing. Raise
an exception if this is attempted, instead.

6fa793d997
2025-07-27 12:17:23 +00:00
Kazuki Yamaguchi
64e8368f5b [ruby/openssl] lib/openssl.rb: require files in alphabetical order
This list was originally in alphabetical order. Sort it again.

This change should be safe since the .rb sources should only depend on
the extension and not each other.

eb3998728a
2025-07-27 12:16:33 +00:00
Nobuyoshi Nakada
0adecf500a
[ruby/json] Keep indentation consistent across functions [ci skip]
1988a3ae4c
2025-07-27 16:35:14 +09:00
Nobuyoshi Nakada
f5aee2480a [ruby/json] Functions defined in headers should be static inline
If `load_uint8x16_4` has an external linkage, it is defined in
both `generator` and `parser` extension libraries.  This duplicate
symbol causes a linker error when `--with-static-linked-ext` is
given, on some platforms.

020693b17a
2025-07-27 15:08:19 +09:00
Jean Boussier
93eed37e66 [ruby/json] Release 2.13.1
cfe9337eda
2025-07-25 11:11:24 +09:00
Jean Boussier
069a24c93c [ruby/json] Don't assume __builtin_cpu_supports exists
Fix: https://github.com/ruby/json/issues/827

On very old compilers it might not exist, at that point
might as well skip SIMD entirely.

da878435dc
2025-07-25 11:11:23 +09:00
John Hawthorn
b48904273a [ruby/json] Fix missing write barrier on Generator State
Found by wbcheck

   WBCHECK ERROR: Missed write barrier detected!
     Parent object: 0x7b7b8487c450 (wb_protected: true)
       rb_obj_info_dump: 0x00007b7b8487c450 JSON/Generator/State/JSON::Ext::Generator::State JSON/Generator/State
     Reference counts - snapshot: 1, writebarrier: 0, current: 6, missed: 5
     Missing reference to: 0x7b7b82f35a10
       rb_obj_info_dump: 0x00007b7b82f35a10 T_STRING/String  len: 1, capa: 15 "1"
     Missing reference to: 0x7b7b82f35e90
       rb_obj_info_dump: 0x00007b7b82f35e90 T_STRING/String  len: 1, capa: 15 "2"
     Missing reference to: 0x7b7b83629e50
       rb_obj_info_dump: 0x00007b7b83629e50 T_STRING/String  len: 1, capa: 15 "3"
     Missing reference to: 0x7b7b83b62190
       rb_obj_info_dump: 0x00007b7b83b62190 T_STRING/String  len: 1, capa: 15 "4"
     Missing reference to: 0x7b7b83629490
       rb_obj_info_dump: 0x00007b7b83629490 T_STRING/String  len: 1, capa: 15 "5"

c24342d801
2025-07-25 11:11:21 +09:00
Peter Zhu
f186f2cb70 Remove unused imemo_parser_strterm 2025-07-24 09:49:13 -04:00
Stan Lo
78820e86c7 Update doc for ObjectSpace.memsize_of 2025-07-23 15:49:04 -04:00
Yusuke Endoh
7e64a68252 Prevent a warning: old-style function definition
ipsocket.c:57:1: warning: old-style function definition [-Wold-style-definition]
   57 | current_clocktime()
      | ^~~~~~~~~~~~~~~~~
2025-07-23 16:46:01 +09:00
Jun Aruga
7bb48f87f3 [ruby/openssl] ssl: add SSLSocket#sigalg, #peer_sigalg, #group
These methods are useful to test post-quantum cryptography (PQC) cases.

434ef74452
2025-07-22 16:51:02 +00:00
Jean Boussier
1e65f0d93e
[ruby/json] Release 2.13.0
8d08494dee
2025-07-18 14:33:26 +09:00
Daisuke Aritomo
a46309d19a
Flag rsock_raise_user_specified_timeout() as NORETURN (#13928)
This suppresses this warning:

../../../ext/socket/ipsocket.c: In function ‘rsock_raise_user_specified_timeout’:
../../../ext/socket/ipsocket.c:30:1: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn]
   30 | rsock_raise_user_specified_timeout()
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-07-17 23:01:57 +09:00
Nobuyoshi Nakada
10a2688fc4
Declare rsock_raise_user_specified_timeout as noreturn 2025-07-17 19:47:18 +09:00
Misaki Shioi
ba490059b4
[Feature #21347] Add open_timeout as an overall timeout option for TCPSocket.new (#13909)
* [Feature #21347] Add `open_timeout` as an overall timeout option for `TCPSocket.new`

With this change, `TCPSocket.new` now accepts the `open_timeout` option.
This option raises an exception if the specified number of seconds has elapsed since the start of the method call,
even if the operation is still in the middle of name resolution or connection attempts.

The addition of this option follows the same intent as the previously merged change to `Socket.tcp`.
[Feature #21347](https://bugs.ruby-lang.org/issues/21347)
https://github.com/ruby/ruby/pull/13368

* Tidy up: Extract rsock_raise_user_specified_timeout()

* Added a note to the documentation of `Socket.tcp`

* Fix `rsock_init_inetsock` for `FAST_FALLBACK_INIT_INETSOCK_IMPL`
2025-07-17 18:15:19 +09:00
Hiroshi SHIBATA
146ddf614b [ruby/io-wait] Bump up 0.3.2
1d2b668457
2025-07-17 11:16:30 +09:00
John Hawthorn
71d4518c59 [ruby/erb] Declare escape functions as Ractor-safe
(https://github.com/ruby/erb/pull/63)

fdd45c0d89
2025-07-15 16:30:55 +00:00
Nobuyoshi Nakada
8a31a0792b [DOC] Include pathname_builtin.rb documents 2025-07-15 20:51:16 +09:00
Daisuke Aritomo
b896f80598
[Bug #21512] Socket.tcp_with_fast_fallback: Pass proper addr family to getaddrinfo (#13878)
Socket.tcp_with_fast_fallback: Pass proper addr family to getaddrinfo

Addrinfo.getaddrinfo expects Socket::AF_INET or Socket::AF_INET6 as its
third argument (family). However Socket.tcp_with_fast_fallback was
incorrectly passing :ipv4 or :ipv6.

Repro:

    require 'socket'
    Socket.tcp_with_fast_fallback('example.com', 80, '127.0.0.1')

Expected behavior: Returns a Socket object
Actual: Raises unknown socket domain: ipv4 (SocketError)
2025-07-15 20:38:57 +09:00
Hiroshi SHIBATA
ea880e624e [ruby/etc] Bump up v1.4.6
c9c9b9d15e
2025-07-15 07:24:28 +00:00
Hiroshi SHIBATA
2ffd6c28ed [ruby/io-nonblock] Bump up 0.3.2
7285725885
2025-07-15 06:26:44 +00:00
Hiroshi SHIBATA
8ea57040f0 [ruby/io-console] Bump up 0.8.1
01071a174a
2025-07-15 06:01:01 +00:00
Nobuyoshi Nakada
a6f0a24e19
Remove no longer used ext/pathname/depend [ci skip] 2025-07-15 14:48:34 +09:00
Hiroshi SHIBATA
98ea78f347 Make Pathname to embedded class 2025-07-15 11:17:51 +09:00
Nobuyoshi Nakada
dbf7a0c713 [ruby/io-wait] [Bug #21509] [DOC] Correct IO#wait description
c65af887a1
2025-07-12 13:32:33 +00:00