From 02d2a7975e26d1acd2ed8f10c33b8715de492dee Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 5 Jul 2018 15:38:20 +0200 Subject: [PATCH] Fix multiple inclusion of OpenVPN3 header with OPENPVN_EXTERN To bundle ptcore and openvpncli into the same shared library for OpenVPN Connect, the two libraries need both to include OpenVPN (or parts of it). Ptcore defines OPENVPN_EXTERN as extern to define the symbols as extern in that library but a few places are missing proper weak symbol (inline) or extern declaration. --- openvpn/common/bigmutex.hpp | 2 +- openvpn/common/hexstr.hpp | 2 +- openvpn/common/string.hpp | 2 +- openvpn/mbedtls/pki/x509cert.hpp | 11 ++++------- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/openvpn/common/bigmutex.hpp b/openvpn/common/bigmutex.hpp index ebd1667f..134f65b0 100644 --- a/openvpn/common/bigmutex.hpp +++ b/openvpn/common/bigmutex.hpp @@ -36,7 +36,7 @@ namespace openvpn { namespace bigmutex { - std::recursive_mutex the_recursive_mutex; + OPENVPN_EXTERN std::recursive_mutex the_recursive_mutex; } #ifdef OPENVPN_ENABLE_BIGMUTEX diff --git a/openvpn/common/hexstr.hpp b/openvpn/common/hexstr.hpp index 1d69ccca..3024fac4 100644 --- a/openvpn/common/hexstr.hpp +++ b/openvpn/common/hexstr.hpp @@ -461,7 +461,7 @@ namespace openvpn { * of the input value. The result will always contain only * two characters. */ - std::string render_hex_number(unsigned char uc, const bool caps=false) + inline std::string render_hex_number(unsigned char uc, const bool caps=false) { RenderHexByte b(uc, caps); return std::string(b.str2(), 2); diff --git a/openvpn/common/string.hpp b/openvpn/common/string.hpp index 7fa386a2..bf6e56da 100644 --- a/openvpn/common/string.hpp +++ b/openvpn/common/string.hpp @@ -223,7 +223,7 @@ namespace openvpn { } // return the first line (without newline) of a multi-line string - std::string first_line(const std::string& str) + inline std::string first_line(const std::string& str) { const size_t pos = str.find_first_of('\n'); if (pos != std::string::npos) diff --git a/openvpn/mbedtls/pki/x509cert.hpp b/openvpn/mbedtls/pki/x509cert.hpp index 11b8434f..81b26324 100644 --- a/openvpn/mbedtls/pki/x509cert.hpp +++ b/openvpn/mbedtls/pki/x509cert.hpp @@ -93,14 +93,14 @@ namespace openvpn { size_t olen = 0; int ret; - ret = mbedtls_pem_write_buffer(begin_cert.c_str(), end_cert.c_str(), der, + ret = mbedtls_pem_write_buffer(begin_cert, end_cert, der, der_size, NULL, 0, &olen); if (ret != MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) throw MbedTLSException("X509Cert::extract: can't calculate PEM size"); BufferAllocated buff(olen, 0); - ret = mbedtls_pem_write_buffer(begin_cert.c_str(), end_cert.c_str(), der, + ret = mbedtls_pem_write_buffer(begin_cert, end_cert, der, der_size, buff.data(), buff.max_size(), &olen); if (ret) throw MbedTLSException("X509Cert::extract: can't write PEM buffer"); @@ -158,12 +158,9 @@ namespace openvpn { } } - static const std::string begin_cert; - static const std::string end_cert; + constexpr static const char* begin_cert = "-----BEGIN CERTIFICATE-----\n";; + constexpr static const char* end_cert = "-----END CERTIFICATE-----\n";; }; - - const std::string X509Cert::begin_cert = "-----BEGIN CERTIFICATE-----\n"; - const std::string X509Cert::end_cert = "-----END CERTIFICATE-----\n"; } }