Skip to content

Commit e6043eb

Browse files
authored
Merge pull request #5 from jonasdn/jonasdn/address_regex
Connection: Allow address of less than 10 hex char
2 parents 82f0668 + fb08765 commit e6043eb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Connection.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Connection::Connection(const std::string &uri)
2222
// "radio://*/80/2M/E7E7E7E7E7" -> auto-pick radio
2323
// "radio://*/80/2M/*" -> broadcast/P2P sniffing on channel 80
2424

25-
const std::regex uri_regex("(usb:\\/\\/(\\d+)|radio:\\/\\/(\\d+|\\*)\\/(\\d+)\\/(250K|1M|2M)\\/([a-fA-F0-9]{10}|\\*)(\\?[\\w=&]+)?)");
25+
const std::regex uri_regex("(usb:\\/\\/(\\d+)|radio:\\/\\/(\\d+|\\*)\\/(\\d+)\\/(250K|1M|2M)\\/([a-fA-F0-9]+|\\*)(\\?[\\w=&]+)?)");
2626
std::smatch match;
2727
if (!std::regex_match(uri, match, uri_regex)) {
2828
std::stringstream sstr;
@@ -64,6 +64,13 @@ Connection::Connection(const std::string &uri)
6464
} else if (match[5].str() == "2M") {
6565
impl_->datarate_ = Crazyradio::Datarate_2MPS;
6666
}
67+
68+
// Address is represented by 40 bytes => 10 hex chars max
69+
if (match[6].str().length() > 10) {
70+
std::stringstream sstr;
71+
sstr << "Invalid uri (" << uri << ")!";
72+
throw std::runtime_error(sstr.str());
73+
}
6774
impl_->address_ = std::stoull(match[6].str(), nullptr, 16);
6875

6976
// parse flags

0 commit comments

Comments
 (0)