Skip to content

Commit 79fbb22

Browse files
committed
Merge branch 'maint-3.1' into maint-3.2
* maint-3.1: Ruby/OpenSSL 3.1.1 Ruby/OpenSSL 3.0.3 digest: make output buffer String independent in #finish cipher: make output buffer String independent
2 parents 1f07615 + 82548a4 commit 79fbb22

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

History.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Notable changes
3838
[[GitHub #141]](https://github.com/ruby/openssl/pull/141)
3939

4040

41+
Version 3.1.1
42+
=============
43+
44+
Merged changes in 3.0.3.
45+
46+
4147
Version 3.1.0
4248
=============
4349

@@ -74,6 +80,31 @@ Notable changes
7480
LibreSSL 3.6 and Ed25519 support in LibreSSL 3.7.
7581

7682

83+
Version 3.0.3
84+
=============
85+
86+
Bug fixes
87+
---------
88+
89+
* Fix a performance regression introduced in v2.1.3 on a buffered write to
90+
`SSLSocket`.
91+
[[GitHub #706]](https://github.com/ruby/openssl/pull/706)
92+
* Fix `OpenSSL::PKCS7` to handle PKCS#7 structures without content.
93+
[[GitHub #690]](https://github.com/ruby/openssl/pull/690)
94+
[[GitHub #752]](https://github.com/ruby/openssl/pull/752)
95+
* Fix `OpenSSL::ASN1::ObjectId#==` with OIDs without a known name.
96+
[[GitHub #791]](https://github.com/ruby/openssl/issues/791)
97+
[[GitHub #792]](https://github.com/ruby/openssl/pull/792)
98+
* Fix `OpenSSL::X509::Certificate#crl_uris` to handle CDP with multiple CRL
99+
URIs.
100+
[[GitHub #775]](https://github.com/ruby/openssl/issues/775)
101+
[[GitHub #776]](https://github.com/ruby/openssl/pull/776)
102+
* Fix `OpenSSL::Cipher#update` to always make the output buffer `String`
103+
independent.
104+
[[Bug #20937]](https://bugs.ruby-lang.org/issues/20937)
105+
[[GitHub #824]](https://github.com/ruby/openssl/pull/824)
106+
107+
77108
Version 3.0.2
78109
=============
79110

ext/openssl/ossl_cipher.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ ossl_cipher_update(int argc, VALUE *argv, VALUE self)
408408
str = rb_str_new(0, out_len);
409409
} else {
410410
StringValue(str);
411-
rb_str_resize(str, out_len);
411+
if ((long)rb_str_capacity(str) >= out_len)
412+
rb_str_modify(str);
413+
else
414+
rb_str_modify_expand(str, out_len - RSTRING_LEN(str));
412415
}
413416

414417
if (!ossl_cipher_update_long(ctx, (unsigned char *)RSTRING_PTR(str), &out_len, in, in_len))

ext/openssl/ossl_digest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
232232
str = rb_str_new(NULL, out_len);
233233
} else {
234234
StringValue(str);
235+
rb_str_modify(str);
235236
rb_str_resize(str, out_len);
236237
}
237238

test/openssl/test_cipher.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,30 @@ def test_ctr_if_exists
128128
assert_equal pt, cipher.update(ct) << cipher.final
129129
end
130130

131+
def test_update_with_buffer
132+
cipher = OpenSSL::Cipher.new("aes-128-ecb").encrypt
133+
cipher.random_key
134+
expected = cipher.update("data") << cipher.final
135+
assert_equal 16, expected.bytesize
136+
137+
# Buffer is supplied
138+
cipher.reset
139+
buf = String.new
140+
assert_same buf, cipher.update("data", buf)
141+
assert_equal expected, buf + cipher.final
142+
143+
# Buffer is frozen
144+
cipher.reset
145+
assert_raise(FrozenError) { cipher.update("data", String.new.freeze) }
146+
147+
# Buffer is a shared string [ruby-core:120141] [Bug #20937]
148+
cipher.reset
149+
buf = "x" * 1024
150+
shared = buf[-("data".bytesize + 32)..-1]
151+
assert_same shared, cipher.update("data", shared)
152+
assert_equal expected, shared + cipher.final
153+
end
154+
131155
def test_ciphers
132156
ciphers = OpenSSL::Cipher.ciphers
133157
assert_kind_of Array, ciphers

0 commit comments

Comments
 (0)