Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix segv in Timestamp::{Request,Response,TokenInfo}.new #407

Merged
merged 1 commit into from Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions ext/openssl/ossl_ts.c
Expand Up @@ -205,8 +205,10 @@ ossl_ts_req_initialize(int argc, VALUE *argv, VALUE self)
in = ossl_obj2bio(&arg);
ts_req = d2i_TS_REQ_bio(in, &ts_req);
BIO_free(in);
if (!ts_req)
if (!ts_req) {
DATA_PTR(self) = NULL;
ossl_raise(eTimestampError, "Error when decoding the timestamp request");
}
DATA_PTR(self) = ts_req;

return self;
Expand Down Expand Up @@ -529,8 +531,10 @@ ossl_ts_resp_initialize(VALUE self, VALUE der)
in = ossl_obj2bio(&der);
ts_resp = d2i_TS_RESP_bio(in, &ts_resp);
BIO_free(in);
if (!ts_resp)
if (!ts_resp) {
DATA_PTR(self) = NULL;
ossl_raise(eTimestampError, "Error when decoding the timestamp response");
}
DATA_PTR(self) = ts_resp;

return self;
Expand Down Expand Up @@ -871,8 +875,10 @@ ossl_ts_token_info_initialize(VALUE self, VALUE der)
in = ossl_obj2bio(&der);
info = d2i_TS_TST_INFO_bio(in, &info);
BIO_free(in);
if (!info)
if (!info) {
DATA_PTR(self) = NULL;
ossl_raise(eTimestampError, "Error when decoding the timestamp token info");
}
DATA_PTR(self) = info;

return self;
Expand Down
18 changes: 18 additions & 0 deletions test/openssl/test_ts.rb
Expand Up @@ -181,6 +181,12 @@ def test_request_encode_decode
assert_equal(42, qer2.nonce)
end

def test_request_invalid_asn1
assert_raise(OpenSSL::Timestamp::TimestampError) do
OpenSSL::Timestamp::Request.new("*" * 44)
end
end

def test_response_constants
assert_equal(0, OpenSSL::Timestamp::Response::GRANTED)
assert_equal(1, OpenSSL::Timestamp::Response::GRANTED_WITH_MODS)
Expand Down Expand Up @@ -333,6 +339,12 @@ def test_response_bad_purpose
end
end

def test_response_invalid_asn1
assert_raise(OpenSSL::Timestamp::TimestampError) do
OpenSSL::Timestamp::Response.new("*" * 44)
end
end

def test_no_cert_requested
req = OpenSSL::Timestamp::Request.new
req.algorithm = "SHA1"
Expand Down Expand Up @@ -585,6 +597,12 @@ def test_token_info_creation
assert_equal(123, info.nonce)
end

def test_token_info_invalid_asn1
assert_raise(OpenSSL::Timestamp::TimestampError) do
OpenSSL::Timestamp::TokenInfo.new("*" * 44)
end
end

private

def assert_cert expected, actual
Expand Down