mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-19 19:52:15 +02:00
Fix RouteBase string formatting bug
When correcting conversion issues in RouteBase a to_string bug was introduced which caused some characters to be escaped when inserted to the string, for example a prefix_len of 0 would render as "\0" rather than inserting '0'. The std::ios::binary flag does not seem to prevent this for std::ostringstream so I have cast the data member up to uint16_t which should be safe, and solves the issue. Added a unit test to demonstrate the issue. Old code output was "0.0.0.0/\0", now outputs "0.0.0.0/0" as expected. Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
This commit is contained in:
parent
e150bb3985
commit
dd115d2e83
@ -150,7 +150,7 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
|
||||
std::string to_string() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << address << '/' << prefix_length;
|
||||
os << address << '/' << static_cast<uint16_t>(prefix_length);
|
||||
if (!gateway.empty())
|
||||
os << " -> " << gateway;
|
||||
if (metric >= 0)
|
||||
|
@ -67,6 +67,7 @@ add_executable(coreUnitTests
|
||||
test_streq.cpp
|
||||
test_time.cpp
|
||||
test_typeindex.cpp
|
||||
test_tun_builder.cpp
|
||||
test_userpass.cpp
|
||||
test_validatecreds.cpp
|
||||
test_weak.cpp
|
||||
|
14
test/unittests/test_tun_builder.cpp
Normal file
14
test/unittests/test_tun_builder.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <openvpn/tun/builder/capture.hpp>
|
||||
|
||||
TEST(tun_builder, to_string_zero)
|
||||
{
|
||||
auto rb = openvpn::TunBuilderCapture::RouteBase();
|
||||
|
||||
rb.address = "0.0.0.0";
|
||||
rb.prefix_length = 0;
|
||||
|
||||
EXPECT_EQ(rb.to_string(), "0.0.0.0/0");
|
||||
}
|
Loading…
Reference in New Issue
Block a user