Skip to content

Commit b9147bf

Browse files
committed
reject short IPv4 address forms in default FromStr parser
* shouldn't have allowed that in the first place. 192.168 could mean either 192.0.0.168 ("inet_addr") or 192.168.0.0 (previously parsed it as the latter) * also "192.168" should never have meant 192.168.0.0/32; 192.168.0.0/16 would have been way more useful (parse_short_ipv4_address_as_cidr provides this)
1 parent e6ee6d6 commit b9147bf

File tree

12 files changed

+14
-153
lines changed

12 files changed

+14
-153
lines changed

src/cidr/any.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ impl FromStr for AnyIpCidr {
247247
type Err = NetworkParseError;
248248

249249
fn from_str(s: &str) -> Result<Self, NetworkParseError> {
250-
// TODO: use strict FromStr::from_str address parsing with version bump
251-
crate::parsers::parse_any_cidr(
252-
s,
253-
crate::local_addr_parser::ParseableAddress::address_from_str,
254-
)
250+
crate::parsers::parse_any_cidr(s, str::parse)
255251
}
256252
}
257253

src/cidr/combined.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use core::{
88
str::FromStr,
99
};
1010

11-
use super::from_str::cidr_from_str;
1211
use crate::{
1312
errors::*,
1413
internal_traits::PrivCidr,
@@ -231,7 +230,7 @@ impl FromStr for IpCidr {
231230
type Err = NetworkParseError;
232231

233232
fn from_str(s: &str) -> Result<Self, NetworkParseError> {
234-
cidr_from_str(s)
233+
crate::parsers::parse_cidr(s, FromStr::from_str)
235234
}
236235
}
237236

src/cidr/direct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use core::{
1010
str::FromStr,
1111
};
1212

13-
use super::from_str::cidr_from_str;
1413
use crate::{
1514
errors::*,
1615
internal_traits::{
@@ -272,7 +271,7 @@ macro_rules! impl_cidr_for {
272271
type Err = NetworkParseError;
273272

274273
fn from_str(s: &str) -> Result<$n, NetworkParseError> {
275-
cidr_from_str(s)
274+
crate::parsers::parse_cidr(s, FromStr::from_str)
276275
}
277276
}
278277

src/cidr/from_str.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/cidr/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub use self::any::AnyIpCidr;
33
mod any;
44
mod combined;
55
mod direct;
6-
mod from_str;
76
mod serde;
87

98
#[cfg(feature = "bitstring")]

src/cidr/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ fn parse_v4_8bit() {
460460
}
461461

462462
#[test]
463+
#[should_panic(expected = "invalid IPv4 address syntax")]
463464
fn parse_v4_8bit_short() {
464465
test_v4(
465466
"10/8",
@@ -482,6 +483,7 @@ fn parse_v4_0bit() {
482483
}
483484

484485
#[test]
486+
#[should_panic(expected = "invalid IPv4 address syntax")]
485487
fn parse_v4_0bit_short() {
486488
test_v4(
487489
"0/0",

src/inet/combined.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use core::{
88
str::FromStr,
99
};
1010

11-
use super::from_str::inet_from_str;
1211
use crate::{
1312
errors::*,
1413
internal_traits::PrivInet,
@@ -336,7 +335,7 @@ impl FromStr for IpInet {
336335
type Err = NetworkParseError;
337336

338337
fn from_str(s: &str) -> Result<Self, NetworkParseError> {
339-
inet_from_str(s)
338+
crate::parsers::parse_inet(s, FromStr::from_str)
340339
}
341340
}
342341

src/inet/direct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use core::{
1010
str::FromStr,
1111
};
1212

13-
use super::from_str::inet_from_str;
1413
use crate::{
1514
errors::*,
1615
internal_traits::{
@@ -369,7 +368,7 @@ macro_rules! impl_inet_for {
369368
type Err = NetworkParseError;
370369

371370
fn from_str(s: &str) -> Result<Self, NetworkParseError> {
372-
inet_from_str(s)
371+
crate::parsers::parse_inet(s, FromStr::from_str)
373372
}
374373
}
375374

src/inet/from_str.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/inet/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod combined;
22
mod direct;
3-
mod from_str;
43
mod serde;
54

65
#[cfg(test)]

0 commit comments

Comments
 (0)