summaryrefslogtreecommitdiff
path: root/ext
AgeCommit message (Collapse)Author
2024-12-07[ruby/openssl] pkey/ec: fix exception class in OpenSSL::PKey::EC.newKazuki Yamaguchi
Fix a copy-and-paste error introduced in commit https://github.com/ruby/openssl/commit/74f6c6175688 (pkey: allocate EVP_PKEY on #initialize, 2021-04-12). It should raise OpenSSL::PKey::ECError instead of OpenSSL::PKey::DSAError. https://github.com/ruby/openssl/commit/b1f6a04abf
2024-12-07[ruby/openssl] make configs shareable when frozenHoneyryderChuck
https://github.com/ruby/openssl/commit/654cb22e21
2024-12-07[ruby/openssl] freeze OpenSSL::Config::DEFAULT_CONFIG_FILEHoneyryderChuck
https://github.com/ruby/openssl/commit/3cc1825435
2024-12-07[ruby/openssl] make config frozen on initializeHoneyryderChuck
https://github.com/ruby/openssl/commit/50599513cf
2024-12-07[ruby/openssl] ssl: handle callback exceptions in SSLSocket#sysread and ↵Kazuki Yamaguchi
#syswrite Check the ID_callback_state ivar after SSL_read() or SSL_write() returns, similar to what ossl_start_ssl() does. Previously, callbacks that can raise a Ruby exception were only called from ossl_start_ssl(). This has changed in OpenSSL 1.1.1. Particularly, the session_new_cb will be called whenever a client receives a NewSessionTicket message, which can happen at any time during a TLS 1.3 connection. https://github.com/ruby/openssl/commit/aac9ce1304
2024-12-07[ruby/openssl] ssl: fix potential exception in servername_cbKazuki Yamaguchi
ssl_servername_cb() is a callback function called from OpenSSL and Ruby exceptions must not be raised from it. Allocate the Array within rb_protect(). https://github.com/ruby/openssl/commit/3a2bf74d35
2024-12-05[ruby/json] Release 2.9.0Jean Boussier
https://github.com/ruby/json/commit/e1f6456499 Notes: Merged: https://github.com/ruby/ruby/pull/12267
2024-12-05[ruby/json] Fix generate(script_safe: true) to not confuse unrelated charactersJean Boussier
Fix: https://github.com/ruby/json/issues/715 The first byte check was missing. https://github.com/ruby/json/commit/93a7f8717d Notes: Merged: https://github.com/ruby/ruby/pull/12267
2024-12-04[ruby/psych] Do not depend on the evaluation order of C argumentsYusuke Endoh
The evaluation order of C arguments is unspecified. `RSTRING_LEN(value)` would fail if the conversion to a String by `StringValuePtr(value)` is not done yet. Coverity Scan found this issue. https://github.com/ruby/psych/commit/d1e6bf323a
2024-12-04Do not depend on the evaluation order of C argumentsYusuke Endoh
The evaluation order of C arguments is unspecified. `RSTRING_LEN(str)` would fails if the conversion to a String by `StringValuePtr` is not done yet. Coverity Scan found this issue. Notes: Merged: https://github.com/ruby/ruby/pull/12209
2024-12-03Fix use of getaddrinfo_shared->lockJohn Hawthorn
In some locations we were using shared->lock and in others &shared->lock, and we were leaking the allocated memory. Notes: Merged: https://github.com/ruby/ruby/pull/12239
2024-12-03[ruby/io-console] Bump up 0.8.0Hiroshi SHIBATA
https://github.com/ruby/io-console/commit/467508a0c6
2024-12-03[ruby/etc] Use same license files with ruby/rubyHiroshi SHIBATA
https://github.com/ruby/etc/commit/8d585ea0c9
2024-12-03[ruby/io-nonblock] Bump up 0.3.1Hiroshi SHIBATA
https://github.com/ruby/io-nonblock/commit/16727a8ab3
2024-12-02[ruby/io-console] Add IO#ttyname that returns the tty name or nilNobuyoshi Nakada
https://github.com/ruby/io-console/commit/fdad351501
2024-12-02[ruby/date] Bump up 3.4.1Hiroshi SHIBATA
https://github.com/ruby/date/commit/a3295ad262
2024-12-02[ruby/io-console] Freeze the version stringNobuyoshi Nakada
https://github.com/ruby/io-console/commit/aa79919f79
2024-12-02[ruby/io-console] Check if `rb_syserr_fail_str` is availableNobuyoshi Nakada
Truffle ruby seems to lack it. https://github.com/ruby/io-console/commit/839c1e80eb
2024-12-02Removed trailing spacesHiroshi SHIBATA
2024-12-02[ruby/strscan] Micro optimize encoding checksJean Boussier
(https://github.com/ruby/strscan/pull/117) Profiling shows a lot of time spent in various encoding check functions. I'm working on optimizing them on the Ruby side, but if we assume most strings are one of the simple 3 encodings, we can skip a lot of overhead. ```ruby require 'strscan' require 'benchmark/ips' source = 10_000.times.map { rand(9999999).to_s }.join(",").force_encoding(Encoding::UTF_8).freeze def scan_to_i(source) scanner = StringScanner.new(source) while number = scanner.scan(/\d+/) number.to_i scanner.skip(",") end end def scan_integer(source) scanner = StringScanner.new(source) while scanner.scan_integer scanner.skip(",") end end Benchmark.ips do |x| x.report("scan.to_i") { scan_to_i(source) } x.report("scan_integer") { scan_integer(source) } x.compare! end ``` Before: ``` ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/strscan/commit/be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- scan.to_i 93.000 i/100ms scan_integer 232.000 i/100ms Calculating ------------------------------------- scan.to_i 933.191 (± 0.2%) i/s (1.07 ms/i) - 4.743k in 5.082597s scan_integer 2.326k (± 0.8%) i/s (429.99 μs/i) - 11.832k in 5.087974s Comparison: scan_integer: 2325.6 i/s scan.to_i: 933.2 i/s - 2.49x slower ``` After: ``` ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/strscan/commit/be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- scan.to_i 96.000 i/100ms scan_integer 274.000 i/100ms Calculating ------------------------------------- scan.to_i 969.489 (± 0.2%) i/s (1.03 ms/i) - 4.896k in 5.050114s scan_integer 2.756k (± 0.1%) i/s (362.88 μs/i) - 13.974k in 5.070837s Comparison: scan_integer: 2755.8 i/s scan.to_i: 969.5 i/s - 2.84x slower ``` https://github.com/ruby/strscan/commit/c02b1ce684
2024-12-02StringScanner#scan_integer support base 16 integers (#116)Jean Boussier
Followup: https://github.com/ruby/strscan/pull/115 `scan_integer` is now implemented in Ruby as to efficiently handle keyword arguments without allocating a Hash. Given the goal of `scan_integer` is to more effciently parse integers without having to allocate an intermediary object, using `rb_scan_args` would defeat the purpose. Additionally, the C implementation now uses `rb_isdigit` and `rb_isxdigit`, because on Windows `isdigit` is locale dependent.
2024-11-30Improve the conditions for clearing the Connection Attempt Delay upon ↵Misaki Shioi
connection failure (#12223) * Improve the conditions for clearing the Connection Attempt Delay upon connection failure This change addresses a case that was overlooked in ruby/ruby#12087. In the previous change, the Connection Attempt Delay was cleared at the point of a connection failure only if both of the following conditions were met: - No other sockets were attempting a connection - There were addresses still available to start a new connection In this update, the second condition has been removed. As a result, if name resolution succeeds after a connection failure and new addresses are obtained, it will be able to immediately attempt a connection to one of them. If there are no sockets attempting a connection, no addresses available for connection, and name resolution has completed, an exception will still be raised as before. --- Additionally, the following minor fixes have been made: * Refactor: Remove unnecessary members Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Ensure to close pipes when `TCPSocket.new` finishes processing (#12181)Misaki Shioi
`TCPSocket.new` with HEv2 uses three threads. The last of these threads to exit closed pipes. However, if pipes were open at the end of the main thread, they would leak. This change avoids this by closing pipes at the end of the main thread. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Allow disable to `fast_fallback` of `TCPSocket.new` (#12210)Misaki Shioi
with `Socket.tcp_fast_fallback=` The functions that `Socket.tcp` had are now also available in `TCPSocket.new`. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-29Remove a useless check if fd is negativeYusuke Endoh
If `slave` is negative, neither `dup2(slave,0)` or `close(slave)` should be executed. I believe this check is completely useless. Notes: Merged: https://github.com/ruby/ruby/pull/12207
2024-11-29[ruby/date] Fix mixed declarations and codeNobuyoshi Nakada
This still support ruby 2.6 which does not require C99. https://github.com/ruby/date/commit/61d849758f
2024-11-29[ruby/date] Suppress compound-token-split-by-macro warningsNobuyoshi Nakada
It was used intentionally. https://github.com/ruby/date/commit/291b40f939
2024-11-28Ensure to free fast_fallback_getaddrinfo_shared with single family (#12199)Misaki Shioi
With https://github.com/ruby/ruby/pull/12156, the memory of the `struct fast_fallback_getaddrinfo_shared` is now allocated even if there is only one address family. This change will always free it when `TCPSocket.new` finishes. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-27[ruby/json] Prevent a warning of "a candidate for gnu_printf format attribute"Yusuke Endoh
GCC 13 prints the following warning. https://rubyci.s3.amazonaws.com/ubuntu/ruby-master/log/20241127T001003Z.log.html.gz ``` compiling generator.c generator.c: In function ‘raise_generator_error’: generator.c:91:5: warning: function ‘raise_generator_error’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format] 91 | VALUE str = rb_vsprintf(fmt, args); | ^~~~~ ``` This change prevents the warning by specifying the format attribute. https://github.com/ruby/json/commit/b8c1490846
2024-11-27[ruby/io-console] Read errno before calling rb_io_path()Alan Wu
Possible fix for recent crashes seen on CI. [BUG] rb_sys_fail_str(<STDIN>) - errno == 0 rb_io_path() calls rb_obj_dup(), which could call initialize_dup in Ruby and clobber errno before rb_sys_fail_str() gets to read errno. So save it out first. (Using separate statements because order of evaluation in function call list is unspecified, and order is important here.) https://github.com/ruby/io-console/commit/0ba400b5e7
2024-11-27Revert "Add a temporal debugging code"Yusuke Endoh
This reverts commit 5bd144c1bb20e22e4d9f5e5e0264820fd3ef8137.
2024-11-27[ruby/strscan] Implement #scan_integer to efficiently parse IntegerJean Boussier
(https://github.com/ruby/strscan/pull/115) Fix: https://github.com/ruby/strscan/issues/113 This allows to directly parse an Integer from a String without needing to first allocate a sub string. Notes: The implementation is limited by design, it's meant as a first step, only the most straightforward, based 10 integers are supported. https://github.com/ruby/strscan/commit/6a3c74b4c8
2024-11-26JSON::GeneratorError expose invalid objectJean Boussier
Fix: https://github.com/ruby/json/issues/710 Makes it easier to debug why a given tree of objects can't be dumped as JSON. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2024-11-26[ruby/json] Stop using `rb_gc_mark_locations`Jean Boussier
It's using `rb_gc_mark_maybe` under the hood, which isn't what we need. https://github.com/ruby/json/commit/e10d0bffcd
2024-11-26[ruby/json] JSON.dump: write directly into the provided IOJean Boussier
Ref: https://github.com/ruby/json/issues/524 Rather than to buffer everything in memory. Unfortunately Ruby doesn't provide an API to write into and IO without first allocating a string, which is a bit wasteful. https://github.com/ruby/json/commit/f017af6c0a
2024-11-25Prevent memory leakYusuke Endoh
``` for (int i = 0; i < arg->family_size; i++) { arg->getaddrinfo_entries[i] = allocate_fast_fallback_getaddrinfo_entry(); if (!(arg->getaddrinfo_entries[i])) rb_syserr_fail(errno, "calloc(3)"); ``` If the allocation fails in the second interation, the memory allocated in the first iteration would be leaked. This change prevents the memory leak by allocating the memory in advance. (The struct name `fast_fallback_getaddrinfo_shared` might no longer be good.) Notes: Merged: https://github.com/ruby/ruby/pull/12163
2024-11-25Fix initialization of `struct wait_fast_fallback_arg::cancelled`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12161
2024-11-25Do not save the last error without sockets in the connection attempt (#12153)Misaki Shioi
* Do not save the last_error if there are no sockets waiting to be connected In this implementation, the results of both name resolution and connection attempts are awaited using select(2). When it returned, the implementation attempted to check for connections even if there were no sockets currently attempting to connect, treating the absence of connected sockets as a connection failure. With this fix, it will no longer check for connections when there are no sockets waiting to be connected. Additionally, the following minor fixes have been made: * Handle failure of getsockopt(2) and removed unnecessary continue in the loop * Tweak: Use common API to check in_progress_fds * Safely call TCPServer.new in test * Set empty writefds when there is no socket waiting to be connected * Enable fast_fallback option Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-24UBF is also required for synchronous name resolution (#12156)Misaki Shioi
`rb_thread_call_without_gvl2` is used to wait for the results of name resolution and connection attempts. When there is only one address family to resolve, the necessary resources were not being passed to the UBF. With this change, the handling of resources has been revised and organized to work consistently, whether there are two address families to resolve or only one. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-23Save the error that occurred during name resolution (#12155)Misaki Shioi
even if a system call error happens after the name resolution failure in the child thread. pipe and write(2) are used to notify the main thread of the name resolution results from the child thread. After name resolution is completed in the child thread, if the call to write(2) fails, the main thread retrieves the resolved addresses. However, when name resolution failed, the corresponding error was not being saved in `last_error`. With this change, name resolution failures will now be saved in last_error even if the write(2) call in the child thread fails. Notes: Merged-By: shioimm <shioi.mm@gmail.com>
2024-11-22[ruby/openssl] Support signing CRLs using Ed25519Josh Cooper
Allow CRLs to be signed using Ed25519 private keys by passing a nil digest. https://github.com/ruby/openssl/commit/b62375bcde
2024-11-22[ruby/openssl] Support signing requests using Ed25519Josh Cooper
Allow requests to be signed using Ed25519 private keys by passing a nil digest. This is similar to commit https://github.com/ruby/openssl/commit/b0fc10009120 when signing certs. Calling PKey#public_key is deprecated and does not work for Ed25519. The same can be accomplished by passing the private key. https://github.com/ruby/openssl/commit/d96090320d
2024-11-22Add a temporal debugging codeYusuke Endoh
... to check the return value of ioctl http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5423172 ``` /tmp/ruby/src/trunk_asan/lib/reline/io/ansi.rb:192: [BUG] rb_sys_fail_str(<STDIN>) - errno == 0 ``` Notes: Merged: https://github.com/ruby/ruby/pull/12147
2024-11-22[Bug #20903] `rb_econv_str_append` arguments expected to be StringNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12145
2024-11-21Fix the usage of reallocYusuke Endoh
http://ci.rvm.jp/results/trunk-repeat50@ruby-sp2-noble-docker/5420911 ``` /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c: In function ‘reallocate_connection_attempt_fds’: /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:292:62: warning: pointer ‘fds’ may be used after ‘realloc’ [-Wuse-after-free] 292 | for (int i = current_capacity; i < new_capacity; i++) fds[i] = -1; | ^ /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:288:9: note: call to ‘realloc’ here 288 | if (realloc(fds, new_capacity * sizeof(int)) == NULL) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
2024-11-20[ruby/zlib] Add support for safe offload of nogvl code.Samuel Williams
(https://github.com/ruby/zlib/pull/89) https://github.com/ruby/zlib/commit/a535271862
2024-11-20[ruby/zlib] Don't call `rb_str_set_len` while released the GVL.Samuel Williams
(https://github.com/ruby/zlib/pull/88) * Only release the GVL where necessary. - Several string manipulation methods were invoked while the GVL was released. This is unsafe. - The mutex protecting multi-threaded access was not covering buffer state manipulation, leading to data corruption and out-of-bounds writes. - Using `rb_str_locktmp` prevents changes to buffer while it's in use. [Bug #20863] https://github.com/ruby/zlib/commit/e445cf3c80
2024-11-20[ruby/psych] Eagerly require `date`.Thierry Deo
https://github.com/ruby/psych/commit/b2aa0032c0
2024-11-20[ruby/etc] Prefer `rb_intern_const` over `rb_intern` for literal stringsNobuyoshi Nakada
https://github.com/ruby/etc/commit/53362d891c
2024-11-20[ruby/digest] Remove obsolete test runner [ci skip]Nobuyoshi Nakada
This file is platform dependent, outdated and already not working. Use `rake` instead. https://github.com/ruby/digest/commit/a2a917dc71