Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion folly/IPAddressV6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ IPAddressV6 IPAddressV6::fromInverseArpaName(const std::string& arpaname) {
size_t pos = 0;
int count = 0;
for (size_t i = 1; i <= pieces.size(); i++) {
ip[pos] = pieces[pieces.size() - i][0];
// Each label is a single hex digit; IPAddressV6 checks that it is hex.
auto const label = pieces[pieces.size() - i];
if (label.size() != 1) {
throw IPAddressFormatException(
fmt::format("Invalid input. Got '{}'", piece));
}
ip[pos] = label[0];
pos++;
count++;
// add ':' every 4 chars
Expand Down
13 changes: 13 additions & 0 deletions folly/test/IPAddressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,19 @@ TEST(IPaddress, fromInverseArpaName) {
fmt::format(
"{}.ip6.arpa",
"3.0.0.0.0.0.0.0.0.0.0.0.c.0.0.b.e.c.a.f.e.f.c.1.0.0.0.0.0.2.6.2")));
// Each label must be exactly one hex digit.
EXPECT_THROW(
IPAddressV6::fromInverseArpaName(
fmt::format(
"{}.ip6.arpa",
"30.0.0.0.0.0.0.0.0.0.0.0.c.0.0.b.e.c.a.f.e.f.c.1.0.0.0.0.0.2.6.2")),
IPAddressFormatException);
EXPECT_THROW(
IPAddressV6::fromInverseArpaName(
fmt::format(
"{}.ip6.arpa",
".0.0.0.0.0.0.0.0.0.0.0.c.0.0.b.e.c.a.f.e.f.c.1.0.0.0.0.0.2.6.2")),
IPAddressFormatException);
}

// Test that invalid string values are killed
Expand Down