0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00
openvpn3/test/unittests/test_tun_builder.cpp
Charlie Vigue dd115d2e83 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>
2024-03-29 03:13:00 +00:00

14 lines
263 B
C++

#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");
}