socket-util: Make address parser check for trailing garbage.
Acked-by: Mark Michelson
@@ -455,6 +455,9 @@ inet_parse_active(const char *target_, uint16_t default_port,
} else if (!port && !default_port) {
VLOG_ERR("%s: port must be specified", target_);
ok = false;
+ } else if (p && p[strspn(p, " \t\r\n")] != '\0') {
+ VLOG_ERR("%s: unexpected characters follow host and port", target_);
+ ok = false;
} else {
ok = parse_sockaddr_components(ss, host, port, default_port, target_);
}
@@ -579,6 +582,9 @@ inet_parse_passive(const char *target_, int default_port,
if (!port && default_port < 0) {
VLOG_ERR("%s: port must be specified", target_);
ok = false;
+ } else if (p && p[strspn(p, " \t\r\n")] != '\0') {
+ VLOG_ERR("%s: unexpected characters follow port and host", target_);
+ ok = false;
} else {
ok = parse_sockaddr_components(ss, host, port, default_port, target_);
}
