Skip to contentSkip to conversation

MSVC: Disable LZ4

PATCH In review Simon Rozman 5 participants 27 messages Mar 21, 2021 – Mar 17, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 MSVC: Disable LZ4

Commit 24596b25 ("build: Remove compat-lz4") removed lz4 compat layer, but openvpn-build\msvc doesn't provide LZ4 library either.

---
 config-msvc.h | 1 -
 1 file changed, 1 deletion(-)
config-msvc.h +0 -1
index e430ca96..53d97902 100644
@@ -9,7 +9,6 @@
 #define ENABLE_FRAGMENT 1
 #define ENABLE_HTTP_PROXY 1
 #define ENABLE_LZO 1
-#define ENABLE_LZ4 1
 #define ENABLE_MANAGEMENT 1
 #define ENABLE_MULTIHOME 1
 #define ENABLE_PKCS11 1
Signature · 1 line
2.30.0.windows.2
#1 lore raw

PATCH 2/5 tun.c: Remove dead code

---
 src/openvpn/tun.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)
src/openvpn/tun.c +0 -34
index 6c51a52d..6b7c8ef1 100644
@@ -85,8 +85,6 @@ static void netsh_command(const struct argv *a, int n, int msglevel);
 
 static const char *netsh_get_id(const char *dev_node, struct gc_arena *gc);
 
-static DWORD get_adapter_index_flexible(const char *name);
-
 static bool
 do_address_service(const bool add, const short family, const struct tuntap *tt)
 {
@@ -4877,38 +4875,6 @@ get_adapter_index(const char *guid)
     return index;
 }
 
-static DWORD
-get_adapter_index_flexible(const char *name)  /* actual name or GUID */
-{
-    struct gc_arena gc = gc_new();
-    DWORD index;
-    index = get_adapter_index_method_1(name);
-    if (index == TUN_ADAPTER_INDEX_INVALID)
-    {
-        index = get_adapter_index_method_2(name);
-    }
-    if (index == TUN_ADAPTER_INDEX_INVALID)
-    {
-        const struct tap_reg *tap_reg = get_tap_reg(&gc);
-        const struct panel_reg *panel_reg = get_panel_reg(&gc);
-        const struct tap_reg *tr = get_adapter_by_name(name, tap_reg, panel_reg);
-        if (tr)
-        {
-            index = get_adapter_index_method_1(tr->guid);
-            if (index == TUN_ADAPTER_INDEX_INVALID)
-            {
-                index = get_adapter_index_method_2(tr->guid);
-            }
-        }
-    }
-    if (index == TUN_ADAPTER_INDEX_INVALID)
-    {
-        msg(M_INFO, "NOTE: could not get adapter index for name/GUID '%s'", name);
-    }
-    gc_free(&gc);
-    return index;
-}
-
 /*
  * Return a string representing a PIP_ADDR_STRING
  */
Signature · 1 line
2.30.0.windows.2
#4 lore raw

PATCH 3/5 interactive.c: Resolve MSVC C4996 warning

In reply to Simon Rozman

It's about using a standard recommended alias for the wcsdup():

Quoted 3 lines

warning C4996: 'wcsdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _wcsdup. See online help for details.

And the documentation says:

Quoted 10 lines

The Microsoft-implemented POSIX function names strdup and wcsdup are deprecated aliases for the _strdup and _wcsdup functions. By default, they generate Compiler warning (level 3) C4996. The names are deprecated because they don't follow the Standard C rules for implementation-specific names. However, the functions are still supported.

We recommend you use _strdup and _wcsdup instead. Or, you can continue to use these function names, and disable the warning. For more information, see Turn off the warning and POSIX function names.

Reference: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup

---
 src/openvpnserv/interactive.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/openvpnserv/interactive.c +3 -3
index 5d5cbfe6..b073a0d5 100644
@@ -899,7 +899,7 @@ ExecCommand(const WCHAR *argv0, const WCHAR *cmdline, DWORD timeout)
     si.cb = sizeof(si);
 
     /* CreateProcess needs a modifiable cmdline: make a copy */
-    cmdline_dup = wcsdup(cmdline);
+    cmdline_dup = _wcsdup(cmdline);
     if (cmdline_dup && CreateProcessW(argv0, cmdline_dup, NULL, NULL, FALSE,
                                       proc_flags, NULL, NULL, &si, &pi) )
     {
@@ -1181,7 +1181,7 @@ SetDNSDomain(const wchar_t *if_name, const char *domain, undo_lists_t *lists)
    /* Add to undo list if domain is non-empty */
    if (err == 0 && wdomain[0] && lists)
    {
-        wchar_t *tmp_name = wcsdup(if_name);
+        wchar_t *tmp_name = _wcsdup(if_name);
         if (!tmp_name || AddListItem(&(*lists)[undo_domain], tmp_name))
         {
             free(tmp_name);
@@ -1272,7 +1272,7 @@ HandleDNSConfigMessage(const dns_cfg_message_t *msg, undo_lists_t *lists)
 
     if (msg->addr_len > 0)
     {
-        wchar_t *tmp_name = wcsdup(wide_name);
+        wchar_t *tmp_name = _wcsdup(wide_name);
         if (!tmp_name || AddListItem(&(*lists)[undo_type], tmp_name))
         {
             free(tmp_name);
Signature · 1 line
2.30.0.windows.2
#8 lore raw

PATCH 4/5 tapctl: Resolve MSVC C4996 warnings

In reply to Simon Rozman

wcsncat() was declared unsafe in favour of wcsncat_s(). However, the string concatenation follows the string length check, making wcsncat() safe too. Code analysis is just not smart enough (yet) to detect this.

The code was refactored to use wcscat_s() MSVC is considering as "safe".

---
 src/tapctl/tap.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
src/tapctl/tap.c +4 -5
index dd4a10a3..3f76c43a 100644
@@ -2,7 +2,7 @@
  *  tapctl -- Utility to manipulate TUN/TAP adapters on Windows
  *            https://community.openvpn.net/openvpn/wiki/Tapctl
  *
- *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2021 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -73,14 +73,13 @@ find_function(const WCHAR *libname, const char *funcname, HMODULE *m)
        return NULL;
     }
 
-    size_t len = _countof(libpath) - wcslen(libpath) - 1;
-    if (len < wcslen(libname) + 1)
+    if (wcslen(libpath) + 1 /*\*/ + wcslen(libname) >= _countof(libpath))
     {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return NULL;
     }
-    wcsncat(libpath, L"\\", len);
-    wcsncat(libpath, libname, len-1);
+    wcscat_s(libpath, _countof(libpath), L"\\");
+    wcscat_s(libpath, _countof(libpath), libname);
 
     *m = LoadLibraryW(libpath);
     if (*m == NULL)
Signature · 1 line
2.30.0.windows.2
#16 lore raw

PATCH 5/5 iservice: Resolve MSVC C4996 warnings

In reply to Simon Rozman

Lots of string functions were declared unsafe in favor of ..._s() counterparts. However, the code already is careful about the buffer size. Code analysis is just not smart enough (yet) to detect this.

The code was refactored to use ..._s() variants MSVC is considering as "safe".

---
 src/openvpnserv/automatic.c   | 8 ++++----
 src/openvpnserv/common.c      | 4 ++--
 src/openvpnserv/interactive.c | 2 +-
 src/openvpnserv/service.c     | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
src/openvpnserv/automatic.c +4 -4
index 3f2ca345..0ba222a0 100644
@@ -137,7 +137,7 @@ modext(LPTSTR dest, size_t size, LPCTSTR src, LPCTSTR newext)
 
     if (size > 0 && (_tcslen(src) + 1) <= size)
     {
-        _tcscpy(dest, src);
+        _tcscpy_s(dest, size, src);
         dest [size - 1] = TEXT('\0');
         i = _tcslen(dest);
         while (i-- > 0)
@@ -154,8 +154,8 @@ modext(LPTSTR dest, size_t size, LPCTSTR src, LPCTSTR newext)
         }
         if (_tcslen(dest) + _tcslen(newext) + 2 <= size)
         {
-            _tcscat(dest, TEXT("."));
-            _tcscat(dest, newext);
+            _tcscat_s(dest, size, TEXT("."));
+            _tcscat_s(dest, size, newext);
             return true;
         }
         dest[0] = TEXT('\0');
@@ -271,7 +271,7 @@ ServiceStartAutomatic(DWORD dwArgc, LPTSTR *lpszArgv)
         BOOL more_files;
         TCHAR find_string[MAX_PATH];
 
-        openvpn_sntprintf(find_string, MAX_PATH, TEXT("%s\\*"), settings.config_dir);
+        openvpn_sntprintf(find_string, _countof(find_string), TEXT("%s\\*"), settings.config_dir);
 
         find_handle = FindFirstFile(find_string, &find_obj);
         if (find_handle == INVALID_HANDLE_VALUE)
src/openvpnserv/common.c +2 -2
index 958643df..48769be4 100644
@@ -37,7 +37,7 @@ openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
     int len = -1;
     if (size > 0)
     {
-        len = _vsntprintf(str, size, format, arglist);
+        len = _vsntprintf_s(str, size, _TRUNCATE, format, arglist);
         str[size - 1] = 0;
     }
     return (len >= 0 && (size_t)len < size);
@@ -311,7 +311,7 @@ get_win_sys_path(void)
 
     if (!GetSystemDirectoryW(win_sys_path, _countof(win_sys_path)))
     {
-        wcsncpy(win_sys_path, default_sys_path, _countof(win_sys_path));
+        wcscpy_s(win_sys_path, _countof(win_sys_path), default_sys_path);
         win_sys_path[_countof(win_sys_path) - 1] = L'\0';
     }
 
src/openvpnserv/interactive.c +1 -1
index b073a0d5..ed83d2a3 100644
@@ -1067,7 +1067,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam
 
     if (IsWindows7OrGreater())
     {
-        wcsncat(cmdline, L" validate=no", ncmdline - wcslen(cmdline) - 1);
+        wcscat_s(cmdline, ncmdline, L" validate=no");
     }
     err = ExecCommand(argv0, cmdline, timeout);
 
src/openvpnserv/service.c +2 -2
index 8efe25f9..8101f83d 100644
@@ -61,14 +61,14 @@ CmdInstallServices()
     TCHAR path[512];
     int i, ret = _service_max;
 
-    if (GetModuleFileName(NULL, path + 1, 510) == 0)
+    if (GetModuleFileName(NULL, path + 1, _countof(path) - 2) == 0)
     {
         _tprintf(TEXT("Unable to install service - %s\n"), GetLastErrorText());
         return 1;
     }
 
     path[0] = TEXT('\"');
-    _tcscat(path, TEXT("\""));
+    _tcscat_s(path, _countof(path), TEXT("\""));
 
     svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
     if (svc_ctl_mgr == NULL)
Signature · 1 line
2.30.0.windows.2
Acked-by on v1 5/5
#17 lore raw

Re: [Openvpn-devel] [PATCH 5/5] iservice: Resolve MSVC C4996 warnings

Am 21.03.21 um 15:46 schrieb Simon Rozman via Openvpn-devel:

Quoted 6 lines

Lots of string functions were declared unsafe in favor of ..._s() counterparts. However, the code already is careful about the buffer size. Code analysis is just not smart enough (yet) to detect this.

The code was refactored to use ..._s() variants MSVC is considering as "safe".

This change changes Windows specifc functions to other windows specific functions that do not emit errors. Test compiled with msvc/clang-cl

Arne

#19 lore raw
In reply to Simon Rozman

Am 21.03.21 um 15:46 schrieb Simon Rozman via Openvpn-devel:

Quoted 2 lines

Commit 24596b25 ("build: Remove compat-lz4") removed lz4 compat layer, but openvpn-build\msvc doesn't provide LZ4 library either.

We should either add lz4 to openvpn-build or change the default of lz4 to disabled in all variant. I don't like the idea that windows has a different default than the other variants.

Arne

#9 lore raw

Re: [Openvpn-devel] [PATCH 4/5] tapctl: Resolve MSVC C4996 warnings

In reply to Simon Rozman

Am 21.03.21 um 15:46 schrieb Simon Rozman via Openvpn-devel:

Quoted 25 lines

wcsncat() was declared unsafe in favour of wcsncat_s(). However, the string concatenation follows the string length check, making wcsncat() safe too. Code analysis is just not smart enough (yet) to detect this.

The code was refactored to use wcscat_s() MSVC is considering as "safe".

---
 src/tapctl/tap.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
src/tapctl/tap.c +1 -1
index dd4a10a3..3f76c43a 100644
@@ -2,7 +2,7 @@
  *  tapctl -- Utility to manipulate TUN/TAP adapters on Windows
  *            https://community.openvpn.net/openvpn/wiki/Tapctl
  *
- *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2021 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2

src/tapctl/tap.c find_function(const WCHAR *libname, const char *funcname, HMODULE *m) · line 76

Quoted 6 lines
src/tapctl/tap.c +1 -2
@@ -73,14 +73,13 @@ find_function(const WCHAR *libname, const char *funcname, HMODULE *m)
        return NULL;
     }
 
-    size_t len = _countof(libpath) - wcslen(libpath) - 1;
-    if (len < wcslen(libname) + 1)
+    if (wcslen(libpath) + 1 /*\*/ + wcslen(libname) >= _countof(libpath))

This random inline comment feels extremely weird.

Arne

#10 lore raw

Re: [Openvpn-devel] [PATCH 4/5] tapctl: Resolve MSVC C4996 warnings

Hi,

Quoted 11 lines
Quoted 1 line

-73,14 +73,13 @@ find_function(const WCHAR *libname, const char

*funcname, HMODULE *m)

src/tapctl/tap.c find_function(const WCHAR *libname, const char *funcname, HMODULE *m)

Quoted 7 lines
        return NULL;
     }
src/tapctl/tap.c +2 -2
-    size_t len = _countof(libpath) - wcslen(libpath) - 1;
-    if (len < wcslen(libname) + 1)
+    if (wcslen(libpath) + 1 /*\*/ + wcslen(libname) >=
+ _countof(libpath))

This random inline comment feels extremely weird.

It's trying to describe the "+ 1" amounts for a backslash \ being strcat-ed in the process below.

Regards, Simon

Acked-by on v1 3/5
#5 lore raw

Re: [Openvpn-devel] [PATCH 3/5] interactive.c: Resolve MSVC C4996 warning

In reply to Simon Rozman

Am 21.03.21 um 15:46 schrieb Simon Rozman via Openvpn-devel:

Quoted 49 lines

It's about using a standard recommended alias for the wcsdup():

Quoted 3 lines

warning C4996: 'wcsdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _wcsdup. See online help for details.

And the documentation says:

Quoted 10 lines

The Microsoft-implemented POSIX function names strdup and wcsdup are deprecated aliases for the _strdup and _wcsdup functions. By default, they generate Compiler warning (level 3) C4996. The names are deprecated because they don't follow the Standard C rules for implementation-specific names. However, the functions are still supported.

We recommend you use _strdup and _wcsdup instead. Or, you can continue to use these function names, and disable the warning. For more information, see Turn off the warning and POSIX function names.

Reference: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup

---
 src/openvpnserv/interactive.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/openvpnserv/interactive.c +2 -2
index 5d5cbfe6..b073a0d5 100644
@@ -899,7 +899,7 @@ ExecCommand(const WCHAR *argv0, const WCHAR *cmdline, DWORD timeout)
     si.cb = sizeof(si);
 
     /* CreateProcess needs a modifiable cmdline: make a copy */
-    cmdline_dup = wcsdup(cmdline);
+    cmdline_dup = _wcsdup(cmdline);
     if (cmdline_dup && CreateProcessW(argv0, cmdline_dup, NULL, NULL, FALSE,
                                       proc_flags, NULL, NULL, &si, &pi) )
     {
@@ -1181,7 +1181,7 @@ SetDNSDomain(const wchar_t *if_name, const char *domain, undo_lists_t *lists)
    /* Add to undo list if domain is non-empty */
    if (err == 0 && wdomain[0] && lists)
    {
-        wchar_t *tmp_name = wcsdup(if_name);
+        wchar_t *tmp_name = _wcsdup(if_name);
         if (!tmp_name || AddListItem(&(*lists)[undo_domain], tmp_name))
         {
             free(tmp_name);

src/openvpnserv/interactive.c HandleDNSConfigMessage(const dns_cfg_message_t *msg, undo_lists_t *lists) · line 1278

Quoted 8 lines
src/openvpnserv/interactive.c +1 -1
@@ -1272,7 +1272,7 @@ HandleDNSConfigMessage(const dns_cfg_message_t *msg, undo_lists_t *lists)
 
     if (msg->addr_len > 0)
     {
-        wchar_t *tmp_name = wcsdup(wide_name);
+        wchar_t *tmp_name = _wcsdup(wide_name);
         if (!tmp_name || AddListItem(&(*lists)[undo_type], tmp_name))
         {
             free(tmp_name);

I can accept the change in this function since it is windows specific but overall I don't think we can reasonable move away from POSIX function names and instead use the names with _ in front of it because that is currently Windows specific. I am not sure what the idea for a portable code is other than to set the _CRT_NONSTDC_NO_DEPRECATE option on Windows.

Arne

#11 lore raw

Re: [Openvpn-devel] [PATCH 4/5] tapctl: Resolve MSVC C4996 warnings

In reply to Simon Rozman

Am 21.03.21 um 17:37 schrieb Simon Rozman:

Quoted 12 lines

Hi,

Quoted 10 lines
Quoted 1 line

-73,14 +73,13 @@ find_function(const WCHAR *libname, const char

*funcname, HMODULE *m)

Quoted 7 lines
        return NULL;
     }
src/tapctl/tap.c +2 -2
-    size_t len = _countof(libpath) - wcslen(libpath) - 1;
-    if (len < wcslen(libname) + 1)
+    if (wcslen(libpath) + 1 /*\*/ + wcslen(libname) >=
+ _countof(libpath))
Quoted 6 lines
Quoted 1 line

This random inline comment feels extremely weird.

It's trying to describe the "+ 1" amounts for a backslash \ being strcat-ed in the process below.

Regards, Simon

I totally didn't get that. I was actually wondering why that is valid code and why the \* doesn't escape the end of comment. I would prefer it be either a longer inline comment or even better use a variable with a normal comment like

/* +1 for the path seperator '\' */
size_t pathlenght = wcslen(libpath) + 1 + wcslen(libname);

Arne

#20 lore raw
In reply to Simon Rozman

Hi,

Quoted 2 lines · Simon Rozman via Openvpn-devel

Commit 24596b25 ("build: Remove compat-lz4") removed lz4 compat layer, but openvpn-build\msvc doesn't provide LZ4 library either.

What would be needed to actually *build* with LZ4 on MSVC? That is, build it as prerequisite as LZO is built?

The idea wasn't to remove LZ4 from builds, just to remove the bundled LZ4 "because all platforms have it now, so we do not need to maintain our own copy". But it seems that was a bit shortsighted wrt windows building...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: tun.c: Remove dead code

In reply to Simon Rozman

Your patch has been applied to the master branch.

"Trivially correct" :-) - but since Windows keeps biting me these days, test built with Ubuntu/MinGW. Just to be sure.

commit 26540310efa8c8955f38974969b317460c075dd4

Author: Simon Rozman via Openvpn-devel
Date:   Sun Mar 21 15:46:24 2021 +0100
     tun.c: Remove dead code

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

[Openvpn-devel] [PATCH applied] Re: interactive.c: Resolve MSVC C4996 warning

In reply to Simon Rozman

I seem to remember we had that discussion in the context of openpvpn-gui already - Problems with the "POSIX compatible" function names, which end up acting on narrow or wide strings depending on compiler settings, compiler version, phase of the moon... can't find that commit, but if MS docs says "this is how windows code should look like", so be it...

I have test compiled stuff on Ubuntu 18 / MinGW, and it compiles. Not tested.

Your patch has been applied to the master branch.

commit 709c3810a1d67e2c4049e852529a0a0d1338c797

Author: Simon Rozman via Openvpn-devel
Date:   Sun Mar 21 15:46:25 2021 +0100
     interactive.c: Resolve MSVC C4996 warning

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#7 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: interactive.c: Resolve MSVC C4996 warning

Hi,

Quoted 2 lines · Gert Doering

commit 709c3810a1d67e2c4049e852529a0a0d1338c797
Author: Simon Rozman via Openvpn-devel

Yeah. Right.

So, apologies for not catching this in time and fixing the Author: line, but this is exactly why I brought up the DMARC issue with Max Fillinger yesterday.

And it royally messes up patchwork as well, because patchwork only cares about mail addresses internally, and shows the name "last seen with that address" - so the Patch from Steffan / Max is now listed as

"Simon Rozman via Openvpn-devel"

as well... https://patchwork.openvpn.net/patch/1628/

*sigh*

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#18 lore raw

[Openvpn-devel] [PATCH applied] Re: iservice: Resolve MSVC C4996 warnings

In reply to Simon Rozman

Tested on Ubuntu 18 / MinGW, compiles.

Checked with the MSVC documentation, seems to make sense :-) - I do notice that we use wcscat_s() in one of these hunks, and _tcscat_s() in another, which seems to be the same thing if _UNICODE is defined (which, I think we do). Maybe an opportunity for another round of cleanup - unify the windows string functions used to "just one variant".

From: line fixed, so Author: is right for this commit.

Your patch has been applied to the master branch.

commit df471f4de8af0cbcf23a4e36910554bea7bd9058

Author: Simon Rozman
Date:   Sun Mar 21 15:46:27 2021 +0100
     iservice: Resolve MSVC C4996 warnings

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#21 lore raw
In reply to Gert Doering

Hi,

Quoted 10 lines
Quoted 2 lines

Commit 24596b25 ("build: Remove compat-lz4") removed lz4 compat layer, but openvpn-build\msvc doesn't provide LZ4 library either.

What would be needed to actually *build* with LZ4 on MSVC? That is, build it as prerequisite as LZO is built?

The idea wasn't to remove LZ4 from builds, just to remove the bundled LZ4 "because all platforms have it now, so we do not need to maintain our own copy". But it seems that was a bit shortsighted wrt windows building...

Thank you and Arne for explaining this. I should have followed the discussion on the OpenVPN meetings. Unfortunately, my workload doesn't allow me to follow on anything these days. So, I am not in condition to prepare LZ4 building in openvpn-build/msvc either.

I can live with LZ4 disabled in my sandbox only.

Shall we drop this patch for now?

Regards, Simon

#12 lore raw

PATCH v2 4/5 tapctl: Resolve MSVC C4996 warnings

In reply to Arne Schwabe

wcsncat() was declared unsafe in favour of wcsncat_s(). However, the string concatenation follows the string length check, making wcsncat() safe too. Code analysis is just not smart enough (yet) to detect this.

The code was refactored to use wcscat_s() MSVC is considering as "safe".

---
 src/tapctl/tap.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
src/tapctl/tap.c +6 -5
index dd4a10a3..563c07f6 100644
@@ -2,7 +2,7 @@
  *  tapctl -- Utility to manipulate TUN/TAP adapters on Windows
  *            https://community.openvpn.net/openvpn/wiki/Tapctl
  *
- *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2021 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -73,14 +73,15 @@ find_function(const WCHAR *libname, const char *funcname, HMODULE *m)
        return NULL;
     }
 
-    size_t len = _countof(libpath) - wcslen(libpath) - 1;
-    if (len < wcslen(libname) + 1)
+    /* +1 for the path seperator '\' */
+    const size_t path_length = wcslen(libpath) + 1 + wcslen(libname);
+    if (path_length >= _countof(libpath))
     {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return NULL;
     }
-    wcsncat(libpath, L"\\", len);
-    wcsncat(libpath, libname, len-1);
+    wcscat_s(libpath, _countof(libpath), L"\\");
+    wcscat_s(libpath, _countof(libpath), libname);
 
     *m = LoadLibraryW(libpath);
     if (*m == NULL)
Signature · 1 line
2.30.0.windows.2
#22 lore raw
In reply to Simon Rozman

Hi,

Quoted 4 lines · Simon Rozman

Thank you and Arne for explaining this. I should have followed the discussion on the OpenVPN meetings. Unfortunately, my workload doesn't allow me to follow on anything these days. So, I am not in condition to prepare LZ4 building in openvpn-build/msvc either.

Understood. Thanks for sending these patches anyway :-)

Quoted 3 lines

I can live with LZ4 disabled in my sandbox only.

Shall we drop this patch for now?

I have set it to "Rejected" (and the discussion is visible in patchwork).

"It should not be so hard", so I'll try to talk Heiko / Arne / Lev into it :-) - might actually be easier than getting generic/build right for MinGW.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
Acked-by on v2 4/5
#13 lore raw

[Openvpn-devel] [PATCH applied] Re: tapctl: Resolve MSVC C4996 warnings

In reply to Simon Rozman

It's the same code change as in v1, just the comment rewritten as Arne asked for (I found the other one okay-ish, but this is more in line with our other code, and indeed "less thinking required on read") and a new helper variable for the total length.

Code looks good, test build on Ubuntu 18/MingW also had no complaints.

Your patch has been applied to the master branch.

commit ef5b922aedead7159718ddbf40fc9f5be1b2b203

Author: Simon Rozman via Openvpn-devel
Date:   Mon Mar 22 08:43:59 2021 +0100
     tapctl: Resolve MSVC C4996 warnings

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21774.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#14 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: tapctl: Resolve MSVC C4996 warnings

Hi,

Quoted 7 lines · Gert Doering

It's the same code change as in v1, just the comment rewritten as Arne asked for (I found the other one okay-ish, but this is more in line with our other code, and indeed "less thinking required on read") and a new helper variable for the total length.

Quoted 7 lines

Code looks good, test build on Ubuntu 18/MingW also had no complaints.

Your patch has been applied to the master branch.

commit ef5b922aedead7159718ddbf40fc9f5be1b2b203

Author: Simon Rozman via Openvpn-devel
Date:   Mon Mar 22 08:43:59 2021 +0100

My local tree was in a slightly funny state (the tip commit had a new ID due to an accidential "git commit --amend" on the wrong head), so I had to rebase and this commit got a new ID

commit e5e9a07e8baee4065b7dfd65736bfa77b8329cfc (HEAD -> master, stable/master, mattock/master, gitlab/master, github/master)

Author: Simon Rozman via Openvpn-devel <[email protected]>
Date:   Mon Mar 22 08:43:59 2021 +0100

tapctl: Resolve MSVC C4996 warnings

(and I forgot to change the From: line again, sorry, again)

Must be Monday :-(

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#23 lore raw
In reply to Gert Doering

For 2.6, I think we should drop openvpn-build for Windows (VS) building and switch to vcpkg for dependencies (openssl, lz4 etc) and cmake as a project file (also supported by VS).

Signature · 1 line
-Lev
#24 lore raw

[Openvpn-devel] Visual Studio building for master/2.6 and LZ4

Hi,

(I have changed the Subject: line to make clear that this is a bigger topic now)

Quoted 3 lines · Lev Stipakov

For 2.6, I think we should drop openvpn-build for Windows (VS) building and switch to vcpkg for dependencies (openssl, lz4 etc) and cmake as a project file (also supported by VS).

I have no opinion there whatsoever... please send patches & trac documentation :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#25 lore raw

Re: [Openvpn-devel] Visual Studio building for master/2.6 and LZ4

Am 22.03.21 um 10:55 schrieb Gert Doering:

Quoted 5 lines

Hi,

(I have changed the Subject: line to make clear that this is a bigger topic now)

Quoted 7 lines
Quoted 3 lines · Lev Stipakov

For 2.6, I think we should drop openvpn-build for Windows (VS) building and switch to vcpkg for dependencies (openssl, lz4 etc) and cmake as a project file (also supported by VS).

I have no opinion there whatsoever... please send patches & trac documentation :-)

I have a very hacky CMakeLists.txt that works well enough to compile with with Clion and MSVC. But the biggest hurdle is that I would need to add pkcs11 to vckpg (and also clean up the cmakelists.txt) file. Also that brings then two ways of building openvpn under Linux/mac/other Unices, one with cmake and one with autoconf/automake and whole discussion about build systems.

Arne

#26 lore raw

Re: [Openvpn-devel] Visual Studio building for master/2.6 and LZ4

In reply to Gert Doering

Il 22/03/21 11:55, Gert Doering ha scritto:

Quoted 9 lines

Hi,

(I have changed the Subject: line to make clear that this is a bigger topic now)

Quoted 3 lines · Lev Stipakov

For 2.6, I think we should drop openvpn-build for Windows (VS) building and switch to vcpkg for dependencies (openssl, lz4 etc) and cmake as a project file (also supported by VS).

I'm not opposed as this sounds more standard than what we have now (opevnpn-build/msvc). We can still cross-compile using openvpn-build/generic if we wish.

This could potentially simplify the automated Windows MSI build process. Right now with Linux + Windows in the mix things are very confusing and fragile.

Quoted 12 lines

I have no opinion there whatsoever... please send patches & trac documentation :-)

gert

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#15 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: tapctl: Resolve MSVC C4996 warnings

In reply to Gert Doering

Hi,

Quoted 11 lines · Gert Doering

My local tree was in a slightly funny state (the tip commit had a new ID due to an accidential "git commit --amend" on the wrong head), so I had to rebase and this commit got a new ID

commit e5e9a07e8baee4065b7dfd65736bfa77b8329cfc (HEAD -> master, stable/master, mattock/master, gitlab/master, github/master)

Author: Simon Rozman via Openvpn-devel <[email protected]>
Date:   Mon Mar 22 08:43:59 2021 +0100

tapctl: Resolve MSVC C4996 warnings

(and I forgot to change the From: line again, sorry, again)

By popular demand (Lev) this was now cherry-picked to 2.5 as well.

commit 64547d552dbcadd826a30a4ba122d590d87504f6 (HEAD -> release/2.5)

Author: Simon Rozman <[email protected]...>
Date:   Mon Mar 22 08:43:59 2021 +0100

tapctl: Resolve MSVC C4996 warnings

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...