1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

Avoid fetch segfault on empty Uri (#1394)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-12-21 04:47:09 -05:00 committed by Ryan Dahl
parent 105a5193b5
commit e4be1209b6
4 changed files with 25 additions and 4 deletions

View file

@ -47,6 +47,17 @@ testPerm({ net: true }, async function responseClone() {
}
});
testPerm({ net: true }, async function fetchEmptyInvalid() {
let err;
try {
await fetch("");
} catch (err_) {
err = err_;
}
assertEqual(err.kind, deno.ErrorKind.InvalidUri);
assertEqual(err.name, "InvalidUri");
});
// TODO(ry) The following tests work but are flaky. There's a race condition
// somewhere. Here is what one of these flaky failures looks like:
//

View file

@ -106,6 +106,9 @@ enum ErrorKind: byte {
HttpParse,
HttpOther,
TooLarge,
// custom errors
InvalidUri,
}
table Cwd {}

View file

@ -1,5 +1,7 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Helpers for serialization.
use errors;
use errors::DenoResult;
use flatbuffers;
use http::header::HeaderName;
use http::uri::Uri;
@ -94,13 +96,14 @@ pub fn serialize_http_response<'bldr>(
pub fn deserialize_request(
header_msg: msg::HttpHeader,
body: Body,
) -> Request<Body> {
) -> DenoResult<Request<Body>> {
let mut r = Request::new(body);
assert!(header_msg.is_request());
let u = header_msg.url().unwrap();
let u = Uri::from_str(u).unwrap();
let u = Uri::from_str(u)
.map_err(|e| errors::new(msg::ErrorKind::InvalidUri, e.to_string()))?;
*r.uri_mut() = u;
if let Some(method) = header_msg.method() {
@ -119,5 +122,5 @@ pub fn deserialize_request(
headers.insert(name, v);
}
}
r
Ok(r)
}

View file

@ -408,7 +408,11 @@ fn op_fetch(
hyper::Body::from(Vec::from(&*data))
};
let req = msg_util::deserialize_request(header, body);
let maybe_req = msg_util::deserialize_request(header, body);
if let Err(e) = maybe_req {
return odd_future(e);
}
let req = maybe_req.unwrap();
if let Err(e) = state.check_net(url) {
return odd_future(e);