From 7e6df65b043e5ab9965b4354bc4b02a9eec26bb5 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 26 Apr 2022 11:23:38 +0200 Subject: [PATCH] fix: Do not panic on invalid Proxy (#450) --- sentry/src/transports/curl.rs | 8 ++++++-- sentry/src/transports/reqwest.rs | 18 ++++++++++++++++-- sentry/src/transports/ureq.rs | 22 ++++++++++++++++------ sentry/tests/test_client.rs | 8 ++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/sentry/src/transports/curl.rs b/sentry/src/transports/curl.rs index dda7244d..e66576c1 100644 --- a/sentry/src/transports/curl.rs +++ b/sentry/src/transports/curl.rs @@ -44,10 +44,14 @@ impl CurlHttpTransport { match (scheme, &http_proxy, &https_proxy) { (Scheme::Https, _, &Some(ref proxy)) => { - handle.proxy(proxy).unwrap(); + if let Err(err) = handle.proxy(proxy) { + sentry_debug!("invalid proxy: {:?}", err); + } } (_, &Some(ref proxy), _) => { - handle.proxy(proxy).unwrap(); + if let Err(err) = handle.proxy(proxy) { + sentry_debug!("invalid proxy: {:?}", err); + } } _ => {} } diff --git a/sentry/src/transports/reqwest.rs b/sentry/src/transports/reqwest.rs index aebb5024..ad99cd7a 100644 --- a/sentry/src/transports/reqwest.rs +++ b/sentry/src/transports/reqwest.rs @@ -33,10 +33,24 @@ impl ReqwestHttpTransport { let client = client.unwrap_or_else(|| { let mut builder = reqwest_::Client::builder(); if let Some(url) = options.http_proxy.as_ref() { - builder = builder.proxy(Proxy::http(url.as_ref()).unwrap()); + match Proxy::http(url.as_ref()) { + Ok(proxy) => { + builder = builder.proxy(proxy); + } + Err(err) => { + sentry_debug!("invalid proxy: {:?}", err); + } + } }; if let Some(url) = options.https_proxy.as_ref() { - builder = builder.proxy(Proxy::https(url.as_ref()).unwrap()); + match Proxy::https(url.as_ref()) { + Ok(proxy) => { + builder = builder.proxy(proxy); + } + Err(err) => { + sentry_debug!("invalid proxy: {:?}", err); + } + } }; builder.build().unwrap() }); diff --git a/sentry/src/transports/ureq.rs b/sentry/src/transports/ureq.rs index 9d8124ca..e05359ae 100644 --- a/sentry/src/transports/ureq.rs +++ b/sentry/src/transports/ureq.rs @@ -34,12 +34,22 @@ impl UreqHttpTransport { let mut builder = AgentBuilder::new(); match (scheme, &options.http_proxy, &options.https_proxy) { - (Scheme::Https, _, &Some(ref proxy)) => { - builder = builder.proxy(Proxy::new(proxy).unwrap()); - } - (_, &Some(ref proxy), _) => { - builder = builder.proxy(Proxy::new(proxy).unwrap()); - } + (Scheme::Https, _, &Some(ref proxy)) => match Proxy::new(proxy) { + Ok(proxy) => { + builder = builder.proxy(proxy); + } + Err(err) => { + sentry_debug!("invalid proxy: {:?}", err); + } + }, + (_, &Some(ref proxy), _) => match Proxy::new(proxy) { + Ok(proxy) => { + builder = builder.proxy(proxy); + } + Err(err) => { + sentry_debug!("invalid proxy: {:?}", err); + } + }, _ => {} } diff --git a/sentry/tests/test_client.rs b/sentry/tests/test_client.rs index 0687fb8f..a3ca737a 100644 --- a/sentry/tests/test_client.rs +++ b/sentry/tests/test_client.rs @@ -71,3 +71,11 @@ fn test_concurrent_init() { .join() .unwrap(); } + +#[test] +fn test_invalid_proxy() { + let _guard = sentry::init(sentry::ClientOptions { + https_proxy: Some("".into()), + ..Default::default() + }); +}