Skip to content

Commit 652f5df

Browse files
committed
shim: check X509_STORE_CTX_get_ex_data return value
Return value of a function 'X509_STORE_CTX_get_ex_data' is dereferenced without checking for NULL, but it is usually checked for this function.
1 parent 04ac8d1 commit 652f5df

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1414

1515
### Fixed
1616

17+
- Unchecked `X509_STORE_CTX_get_ex_data` return value (#16).
18+
1719
## [v1.1.0] - 2024-09-02
1820

1921
The release adds more bindings.

shim.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ int X_SSL_new_index() {
434434
int X_SSL_verify_cb(int ok, X509_STORE_CTX* store) {
435435
SSL* ssl = (SSL *)X509_STORE_CTX_get_ex_data(store,
436436
SSL_get_ex_data_X509_STORE_CTX_idx());
437+
if (ssl == NULL) {
438+
return 0;
439+
}
440+
437441
void* p = SSL_get_ex_data(ssl, get_ssl_idx());
438442
// get the pointer to the go Ctx object and pass it back into the thunk
439443
return go_ssl_verify_cb_thunk(p, ok, store);
@@ -557,6 +561,10 @@ long X_SSL_CTX_set_tlsext_servername_callback(
557561
int X_SSL_CTX_verify_cb(int ok, X509_STORE_CTX* store) {
558562
SSL* ssl = (SSL *)X509_STORE_CTX_get_ex_data(store,
559563
SSL_get_ex_data_X509_STORE_CTX_idx());
564+
if (ssl == NULL) {
565+
return 0;
566+
}
567+
560568
SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
561569
void* p = SSL_CTX_get_ex_data(ssl_ctx, get_ssl_ctx_idx());
562570
// get the pointer to the go Ctx object and pass it back into the thunk

0 commit comments

Comments
 (0)