Skip to content

Commit d973c98

Browse files
authored
Merge pull request #19 from dfinity/igor/fix-extract
Fix crash in extract_host, add test
2 parents 5d2046f + 2d28bee commit d973c98

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/http/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ pub const fn http_method(v: &Method) -> &'static str {
9090
/// Attempts to extract "host" from "host:port" format.
9191
/// Host can be either FQDN or IPv4/IPv6 address.
9292
pub fn extract_host(host_port: &str) -> Option<&str> {
93+
if host_port.is_empty() {
94+
return None;
95+
}
96+
9397
// Cover IPv6 case
9498
if host_port.as_bytes()[0] == b'[' {
9599
host_port.find(']').map(|i| &host_port[0..=i])
@@ -216,8 +220,10 @@ mod test {
216220
Some("[fe80::b696:91ff:fe84:3ae8]")
217221
);
218222

219-
// Unterminated bracket, the only failure case
223+
// Unterminated bracket
220224
assert_eq!(extract_host("[fe80::b696:91ff:fe84:3ae8:123"), None);
225+
// Empty
226+
assert_eq!(extract_host(""), None);
221227
}
222228

223229
#[test]

src/tls/acme/acme.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ use tokio::fs;
1515
use tracing::{debug, info};
1616
use x509_parser::prelude::*;
1717

18-
use crate::tls::extract_sans;
19-
20-
pub use instant_acme;
21-
2218
use super::{AcmeOptions, TokenManager};
19+
use crate::tls::extract_sans;
2320

2421
const FILE_CERT: &str = "cert.pem";
2522
const FILE_KEY: &str = "cert.key";

src/tls/acme/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use async_trait::async_trait;
1212
use derive_new::new;
1313
use strum_macros::{Display, EnumString};
1414

15+
pub use instant_acme;
16+
1517
#[derive(Clone, Display, EnumString, PartialEq, Eq)]
1618
#[strum(serialize_all = "snake_case")]
1719
pub enum Challenge {

0 commit comments

Comments
 (0)