Skip to content

Commit 9389548

Browse files
committed
fix SSL callback
1 parent 0cd6eb7 commit 9389548

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

crates/stdlib/src/ssl.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,31 @@ mod _ssl {
26522652
};
26532653
let initial_context: PyObjectRef = self.context.read().clone().into();
26542654

2655-
let result = callback.call((ssl_sock, server_name_py, initial_context), vm)?;
2655+
// catches exceptions from the callback and reports them as unraisable
2656+
let result = match callback.call((ssl_sock, server_name_py, initial_context), vm) {
2657+
Ok(result) => result,
2658+
Err(exc) => {
2659+
vm.run_unraisable(
2660+
exc,
2661+
Some("in ssl servername callback".to_owned()),
2662+
callback.clone(),
2663+
);
2664+
// Return SSL error like SSL_TLSEXT_ERR_ALERT_FATAL
2665+
let ssl_exc: PyBaseExceptionRef = vm
2666+
.new_os_subtype_error(
2667+
PySSLError::class(&vm.ctx).to_owned(),
2668+
None,
2669+
"SNI callback raised exception",
2670+
)
2671+
.upcast();
2672+
let _ = ssl_exc.as_object().set_attr(
2673+
"reason",
2674+
vm.ctx.new_str("TLSV1_ALERT_INTERNAL_ERROR"),
2675+
vm,
2676+
);
2677+
return Err(ssl_exc);
2678+
}
2679+
};
26562680

26572681
// Check return value type (must be None or integer)
26582682
if !vm.is_none(&result) {

0 commit comments

Comments
 (0)