summaryrefslogtreecommitdiff
path: root/runtime/ops/http.rs
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2022-10-18 11:28:27 +0900
committerGitHub <noreply@github.com>2022-10-18 11:28:27 +0900
commit44a89dd6dc7864822ddb48d030af519160de90a2 (patch)
tree3a7fe40040372d6118a86276d7d91317ab026de5 /runtime/ops/http.rs
parent74be01273c16b83b1063da1750045b12e095f0c3 (diff)
fix(ext/net): return an error from `startTls` and `serveHttp` if the original connection is captured elsewhere (#16242)
This commit removes the calls to `expect()` on `std::rc::Rc`, which caused Deno to panic under certain situations. We now return an error if `Rc` is referenced by other variables. Fixes #9360 Fixes #13345 Fixes #13926 Fixes #16241 Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/ops/http.rs')
-rw-r--r--runtime/ops/http.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs
index 7a58da361..e751adae8 100644
--- a/runtime/ops/http.rs
+++ b/runtime/ops/http.rs
@@ -1,6 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
+use deno_core::error::bad_resource;
use deno_core::error::bad_resource_id;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
@@ -44,8 +45,11 @@ fn op_http_start(
.resource_table
.take::<TcpStreamResource>(tcp_stream_rid)
{
+ // This TCP connection might be used somewhere else. If it's the case, we cannot proceed with the
+ // process of starting a HTTP server on top of this TCP connection, so we just return a bad
+ // resource error. See also: https://github.com/denoland/deno/pull/16242
let resource = Rc::try_unwrap(resource_rc)
- .expect("Only a single use of this resource should happen");
+ .map_err(|_| bad_resource("TCP stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tcp_stream = read_half.reunite(write_half)?;
let addr = tcp_stream.local_addr()?;
@@ -56,8 +60,11 @@ fn op_http_start(
.resource_table
.take::<TlsStreamResource>(tcp_stream_rid)
{
+ // This TLS connection might be used somewhere else. If it's the case, we cannot proceed with the
+ // process of starting a HTTP server on top of this TLS connection, so we just return a bad
+ // resource error. See also: https://github.com/denoland/deno/pull/16242
let resource = Rc::try_unwrap(resource_rc)
- .expect("Only a single use of this resource should happen");
+ .map_err(|_| bad_resource("TLS stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tls_stream = read_half.reunite(write_half);
let addr = tls_stream.get_ref().0.local_addr()?;
@@ -71,8 +78,11 @@ fn op_http_start(
{
super::check_unstable(state, "Deno.serveHttp");
+ // This UNIX socket might be used somewhere else. If it's the case, we cannot proceed with the
+ // process of starting a HTTP server on top of this UNIX socket, so we just return a bad
+ // resource error. See also: https://github.com/denoland/deno/pull/16242
let resource = Rc::try_unwrap(resource_rc)
- .expect("Only a single use of this resource should happen");
+ .map_err(|_| bad_resource("UNIX stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let unix_stream = read_half.reunite(write_half)?;
let addr = unix_stream.local_addr()?;