[ovs-dev,02/11] socket-util: Make address parser check for trailing garbage.

Message ID 20180413172655.31638-2-blp@ovn.org
State Accepted
Headers show
Series
  • [ovs-dev,01/11] socket-util: Fix error in comment on ss_format_address().
Related show

Commit Message

Ben Pfaff April 13, 2018, 5:26 p.m.
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/socket-util.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/lib/socket-util.c b/lib/socket-util.c
index 5485e3b515dd..86ac4d433a2d 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -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_);
     }