Skip to content

Commit c5f6a97

Browse files
committed
Prevent out of bounds check on the password method
1 parent 17f3d20 commit c5f6a97

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,10 @@ impl Url {
752752
pub fn password(&self) -> Option<&str> {
753753
// This ':' is not the one marking a port number since a host can not be empty.
754754
// (Except for file: URLs, which do not have port numbers.)
755-
if self.has_authority() && self.byte_at(self.username_end) == b':' {
755+
if self.has_authority()
756+
&& self.username_end < self.serialization.len() as u32
757+
&& self.byte_at(self.username_end) == b':'
758+
{
756759
debug_assert!(self.byte_at(self.host_start - 1) == b'@');
757760
Some(self.slice(self.username_end + 1..self.host_start - 1))
758761
} else {

0 commit comments

Comments
 (0)