From 4f0a20ec687334d94388402a56dbe93b726aac6b Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Tue, 2 Sep 2014 17:37:25 -0700 Subject: [PATCH] Handle whitespace separating an 'ip port' correctly (RIPD-552) --- beast/net/detail/Parse.h | 14 ++++++++++++++ beast/net/impl/IPEndpoint.cpp | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/beast/net/detail/Parse.h b/beast/net/detail/Parse.h index 4f4f398b..b3ec58c7 100644 --- a/beast/net/detail/Parse.h +++ b/beast/net/detail/Parse.h @@ -42,6 +42,20 @@ bool expect (InputStream& is, char v) return false; } +/** Require and consume whitespace from the input. + @return `true` if the character matched. +*/ +template +bool expect_whitespace (InputStream& is) +{ + char c; + if (is.get(c) && isspace(c)) + return true; + is.unget(); + is.setstate (std::ios_base::failbit); + return false; +} + /** Used to disambiguate 8-bit integers from characters. */ template struct integer_holder diff --git a/beast/net/impl/IPEndpoint.cpp b/beast/net/impl/IPEndpoint.cpp index d4a4fe8b..ed15f408 100644 --- a/beast/net/impl/IPEndpoint.cpp +++ b/beast/net/impl/IPEndpoint.cpp @@ -79,14 +79,14 @@ Endpoint Endpoint::from_string_altform (std::string const& s) if (is.rdbuf()->in_avail()>0) { - if (! IP::detail::expect (is, ' ')) + if (! IP::detail::expect_whitespace (is)) return Endpoint(); while (is.rdbuf()->in_avail()>0) { char c; is.get(c); - if (c != ' ') + if (!isspace (c)) { is.unget(); break;