Skip to content

Commit bc787ef

Browse files
authored
fix(links): correct IPv6 address parsing for TLS and QUIC locators (#2138)
Fix IPv6 parsing where `get_*_host()` functions incorrectly handled square brackets, causing "[::1]:7447" to become "[:7447" in HELLO messages. Use `rsplit_once` instead of `split` in host computation.
1 parent eea81bf commit bc787ef

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

io/zenoh-link-commons/src/quic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,11 @@ pub async fn get_quic_addr(address: &Address<'_>) -> ZResult<SocketAddr> {
513513
}
514514

515515
pub fn get_quic_host<'a>(address: &'a Address<'a>) -> ZResult<&'a str> {
516-
address
516+
Ok(address
517517
.as_str()
518-
.split(':')
519-
.next()
520-
.ok_or_else(|| zerror!("Invalid QUIC address").into())
518+
.rsplit_once(':')
519+
.ok_or_else(|| zerror!("Invalid QUIC address"))?
520+
.0)
521521
}
522522

523523
pub fn base64_decode(data: &str) -> ZResult<Vec<u8>> {

io/zenoh-links/zenoh-link-quic/src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,11 @@ pub async fn get_quic_addr(address: &Address<'_>) -> ZResult<SocketAddr> {
507507
}
508508

509509
pub fn get_quic_host<'a>(address: &'a Address<'a>) -> ZResult<&'a str> {
510-
address
510+
Ok(address
511511
.as_str()
512-
.split(':')
513-
.next()
514-
.ok_or_else(|| zerror!("Invalid QUIC address").into())
512+
.rsplit_once(':')
513+
.ok_or_else(|| zerror!("Invalid QUIC address"))?
514+
.0)
515515
}
516516

517517
pub fn base64_decode(data: &str) -> ZResult<Vec<u8>> {

io/zenoh-links/zenoh-link-tls/src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,11 @@ pub async fn get_tls_addr(address: &Address<'_>) -> ZResult<SocketAddr> {
595595
}
596596

597597
pub fn get_tls_host<'a>(address: &'a Address<'a>) -> ZResult<&'a str> {
598-
address
598+
Ok(address
599599
.as_str()
600-
.split(':')
601-
.next()
602-
.ok_or_else(|| zerror!("Invalid TLS address").into())
600+
.rsplit_once(':')
601+
.ok_or_else(|| zerror!("Invalid TLS address"))?
602+
.0)
603603
}
604604

605605
pub fn get_tls_server_name<'a>(address: &'a Address<'a>) -> ZResult<ServerName<'a>> {

0 commit comments

Comments
 (0)