Skip to contentSkip to conversation

MSVC Fixes for 2.3

Openvpn-devel In review James Yonan 2 participants 13 messages May 8, 2014 – May 20, 2014

lore
Share & tools
lore
#0 lore raw

This series of patches is for the 2.3 branch and fixes MSVC compile issues. Some of these may be applicable to master as well, though I haven't checked yet.

James

#1 lore raw

PATCH 1/6 Fixed several instances of declarations after statements.

---
 src/openvpn/init.c   | 10 ++++++----
 src/openvpn/socket.c |  2 +-
 src/openvpn/win32.c  |  6 +++---
 3 files changed, 10 insertions(+), 8 deletions(-)
src/openvpn/init.c +6 -4
index 52d370b..88883fb 100644
@@ -183,10 +183,12 @@ ce_management_query_proxy (struct context *c)
   if (management)
     {
       gc = gc_new ();
-      struct buffer out = alloc_buf_gc (256, &gc);
-      buf_printf (&out, ">PROXY:%u,%s,%s", (l ? l->current : 0) + 1,
-                  (proto_is_udp (ce->proto) ? "UDP" : "TCP"), np (ce->remote));
-      management_notify_generic (management, BSTR (&out));
+      {
+	struct buffer out = alloc_buf_gc (256, &gc);
+	buf_printf (&out, ">PROXY:%u,%s,%s", (l ? l->current : 0) + 1,
+		    (proto_is_udp (ce->proto) ? "UDP" : "TCP"), np (ce->remote));
+	management_notify_generic (management, BSTR (&out));
+      }
       ce->flags |= CE_MAN_QUERY_PROXY;
       while (ce->flags & CE_MAN_QUERY_PROXY)
         {
src/openvpn/socket.c +1 -1
index 23566f1..7ff14cc 100644
@@ -1227,6 +1227,7 @@ resolve_remote (struct link_socket *sock,
 	      unsigned int flags = sf2gaf(GETADDR_RESOLVE|GETADDR_UPDATE_MANAGEMENT_STATE, sock->sockflags);
 	      int retry = 0;
 	      int status = -1;
+	      struct addrinfo* ai;
 
 	      if (sock->connection_profiles_defined && sock->resolve_retry_seconds == RESOLV_RETRY_INFINITE)
 		{
@@ -1263,7 +1264,6 @@ resolve_remote (struct link_socket *sock,
 		  ASSERT (0);
 		}
 
-		  struct addrinfo* ai;
 		  /* Temporary fix, this need to be changed for dual stack */
 		  status = openvpn_getaddrinfo(flags, sock->remote_host, retry,
 											  signal_received, af, &ai);
src/openvpn/win32.c +3 -3
index 13fd881..f35c96b 100644
@@ -870,6 +870,9 @@ openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned i
           WCHAR *cl = wide_cmd_line (a, &gc);
           WCHAR *cmd = wide_string (a->argv[0], &gc);
 
+          /* this allows console programs to run, and is ignored otherwise */
+          DWORD proc_flags = CREATE_NO_WINDOW;
+
           CLEAR (start_info);
           CLEAR (proc_info);
 
@@ -879,9 +882,6 @@ openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned i
           start_info.dwFlags = STARTF_USESHOWWINDOW;
           start_info.wShowWindow = SW_HIDE;
 
-          /* this allows console programs to run, and is ignored otherwise */
-          DWORD proc_flags = CREATE_NO_WINDOW;
-
           if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, proc_flags, env, NULL, &start_info, &proc_info))
             {
               DWORD exit_status = 0;
Signature · 1 line
1.8.5.5
#3 lore raw

PATCH 2/6 In socket.c, fixed issue where uninitialized value (err) is being passed to to gai_strerror.

In reply to James Yonan
---
 src/openvpn/socket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/openvpn/socket.c +1 -2
index 7ff14cc..6e68c18 100644
@@ -1150,7 +1150,6 @@ resolve_bind_local (struct link_socket *sock)
 	case AF_INET6:
 	    {
 	      int status;
-	      int err;
 	      CLEAR(sock->info.lsa->local.addr.in6);
 	      if (sock->local_host)
 		{
@@ -1173,7 +1172,7 @@ resolve_bind_local (struct link_socket *sock)
 		{
 		  msg (M_FATAL, "getaddr6() failed for local \"%s\": %s",
 		       sock->local_host,
-		       gai_strerror(err));
+		       gai_strerror(status));
 		}
 	      sock->info.lsa->local.addr.in6.sin6_port = htons (sock->local_port);
 	    }
Signature · 1 line
1.8.5.5
#5 lore raw

PATCH 3/6 Explicitly cast the third parameter of setsockopt to const void * to avoid warning.

In reply to James Yonan
---
 src/openvpn/socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/socket.h +1 -1
index 4e7e7f8..793cd9f 100644
@@ -1023,7 +1023,7 @@ static inline void
 link_socket_set_tos (struct link_socket *ls)
 {
   if (ls && ls->ptos_defined)
-    setsockopt (ls->sd, IPPROTO_IP, IP_TOS, &ls->ptos, sizeof (ls->ptos));
+    setsockopt (ls->sd, IPPROTO_IP, IP_TOS, (const void *)&ls->ptos, sizeof (ls->ptos));
 }
 
 #endif
Signature · 1 line
1.8.5.5
#7 lore raw

PATCH 4/6 MSVC 2008 doesn't support dimensioning an array with a const var nor using %z as a printf format specifier.

In reply to James Yonan
---
 src/openvpn/ssl_openssl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
src/openvpn/ssl_openssl.c +3 -4
index 481600a..d845fd7 100644
@@ -261,8 +261,7 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 
   const tls_cipher_name_pair *cipher_pair;
 
-  const size_t openssl_ciphers_size = 4096;
-  char openssl_ciphers[openssl_ciphers_size];
+  char openssl_ciphers[4096];
   size_t openssl_ciphers_len = 0;
   openssl_ciphers[0] = '\0';
 
@@ -301,8 +300,8 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 	}
 
       // Make sure new cipher name fits in cipher string
-      if (((openssl_ciphers_size-1) - openssl_ciphers_len) < current_cipher_len) {
-	msg(M_SSLERR, "Failed to set restricted TLS cipher list, too long (>%zu).", openssl_ciphers_size-1);
+      if (((sizeof(openssl_ciphers)-1) - openssl_ciphers_len) < current_cipher_len) {
+	msg(M_SSLERR, "Failed to set restricted TLS cipher list, too long (>%d).", (int)sizeof(openssl_ciphers)-1);
       }
 
       // Concatenate cipher name to OpenSSL cipher string
Signature · 1 line
1.8.5.5
#9 lore raw

PATCH 5/6 Define PATH_SEPARATOR for MSVC builds.

In reply to James Yonan
---
 config-msvc.h | 3 +++
 1 file changed, 3 insertions(+)
config-msvc.h +3 -0
index 9a95ae6..fa99384 100644
@@ -76,6 +76,9 @@
 
 #define HAVE_OPENSSL_ENGINE 1
 
+#define PATH_SEPARATOR     '\\'
+#define PATH_SEPARATOR_STR "\\"
+
 #ifndef __cplusplus
 #define inline __inline
 #endif
Signature · 1 line
1.8.5.5
#11 lore raw

PATCH 6/6 Fixed some compile issues with show_library_versions()

In reply to James Yonan

* Refactored show_library_versions to work around the fact that some compilers (such as MSVC 2008) can't handle #ifdefs inside of macro references.

* Declare show_library_versions() in options.h because it's referenced by other files such as openvpn.c.

* Declare get_ssl_library_version() as returning const char *, to avoid loss of const qualifier in ssl_openssl.c.

---
 src/openvpn/options.c      | 15 +++++++++------
 src/openvpn/options.h      |  2 ++
 src/openvpn/ssl_backend.h  |  2 +-
 src/openvpn/ssl_openssl.c  |  2 +-
 src/openvpn/ssl_polarssl.c |  2 +-
 5 files changed, 14 insertions(+), 9 deletions(-)
src/openvpn/options.c +9 -6
index 59d7895..8406822 100644
@@ -3439,18 +3439,21 @@ usage_small (void)
 void
 show_library_versions(const unsigned int flags)
 {
-  msg (flags, "library versions: %s%s%s",
 #ifdef ENABLE_SSL
-			get_ssl_library_version(),
+#define SSL_LIB_VER_STR get_ssl_library_version()
 #else
-			"",
+#define SSL_LIB_VER_STR ""
 #endif
 #ifdef ENABLE_LZO
-			", LZO ", lzo_version_string()
+#define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
 #else
-			"", ""
+#define LZO_LIB_VER_STR "", ""
 #endif
-	);
+
+  msg (flags, "library versions: %s%s%s", SSL_LIB_VER_STR, LZO_LIB_VER_STR);
+
+#undef SSL_LIB_VER_STR
+#undef LZO_LIB_VER_STR
 }
 
 static void
src/openvpn/options.h +2 -0
index c6378d8..7bb61e0 100644
@@ -685,6 +685,8 @@ void notnull (const char *arg, const char *description);
 
 void usage_small (void);
 
+void show_library_versions(const unsigned int flags);
+
 void init_options (struct options *o, const bool init_gc);
 void uninit_options (struct options *o);
 
src/openvpn/ssl_backend.h +1 -1
index b37b1e5..fc23175 100644
@@ -472,6 +472,6 @@ void get_highest_preference_tls_cipher (char *buf, int size);
  * return a pointer to a static memory area containing the
  * name and version number of the SSL library in use
  */
-char * get_ssl_library_version(void);
+const char * get_ssl_library_version(void);
 
 #endif /* SSL_BACKEND_H_ */
src/openvpn/ssl_openssl.c +1 -1
index d845fd7..e77b736 100644
@@ -1354,7 +1354,7 @@ get_highest_preference_tls_cipher (char *buf, int size)
   SSL_CTX_free (ctx);
 }
 
-char *
+const char *
 get_ssl_library_version(void)
 {
     return SSLeay_version(SSLEAY_VERSION);
src/openvpn/ssl_polarssl.c +1 -1
index 0dfffd6..e3e3017 100644
@@ -1068,7 +1068,7 @@ get_highest_preference_tls_cipher (char *buf, int size)
   strncpynt (buf, cipher_name, size);
 }
 
-char *
+const char *
 get_ssl_library_version(void)
 {
     static char polar_version[30];
Signature · 1 line
1.8.5.5
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Fixed several instances of declarations after statements.

In reply to James Yonan

ACK.

Your patch has been applied to the release/2.3 branch.

Two of the changes are in "master" already, and the socket.c one has been superseded by Arne's dual-stack code changes.

commit 8adb295ebaef0ddf10ce732df36fa6be2d939c0c

Author: James Yonan
Date:   Thu May 8 16:50:31 2014 -0600
     Fixed several instances of declarations after statements.

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8709
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

[Openvpn-devel] [PATCH applied] Re: In socket.c, fixed issue where uninitialized value (err) is being passed to to gai_strerror.

In reply to James Yonan

ACK.

Your patch has been applied to the release/2.3 branch only.

This code is not present in "master" (most likely due to the dual-stack refactoring).

commit 302655c98503850765f860951a2b80280bc17385

Author: James Yonan
Date:   Thu May 8 16:50:32 2014 -0600
     In socket.c, fixed issue where uninitialized value (err) is being passed to to gai_strerror.

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8713
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Explicitly cast the third parameter of setsockopt to const void * to avoid warning.

In reply to James Yonan

ACK.

Your patch has been applied to the release/2.3 branch only.

"master" has this change as part of 46e02127 already.

commit 36c216556a0de5250040d95ac8f7a8c18b8683b4

Author: James Yonan
Date:   Thu May 8 16:50:33 2014 -0600
     Explicitly cast the third parameter of setsockopt to const void * to avoid warning.

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8708
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#8 lore raw

[Openvpn-devel] [PATCH applied] Re: MSVC 2008 doesn't support dimensioning an array with a const var nor using %z as a printf format specifier.

In reply to James Yonan

ACK.

Your patch has been applied to the release/2.3 branch only.

"master" already has the change, as part of 46e02127

commit 11fbe93b08180acddc8ac301e6eff6553b9f78e1

Author: James Yonan
Date:   Thu May 8 16:50:34 2014 -0600
     MSVC 2008 doesn't support dimensioning an array with a const var nor using %z as a printf format specifier.

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8710
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#10 lore raw

[Openvpn-devel] [PATCH applied] Re: Define PATH_SEPARATOR for MSVC builds.

In reply to James Yonan

ACK.

Your patch has been applied to the release/2.3 and master branches.

commit 3e8e496008f6634234d5867a22d7a1c03a5bf164 (release/2.3) commit e583cae83b8c2590dad0c4ce238bc2a45196f914 (master)

Author: James Yonan
Date:   Thu May 8 16:50:35 2014 -0600
     Define PATH_SEPARATOR for MSVC builds.

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8714
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#12 lore raw

[Openvpn-devel] [PATCH applied] Re: Fixed some compile issues with show_library_versions()

In reply to James Yonan

ACK, thanks for cleaning up my "proof of concept" ugliness :-)

Your patch has been applied to the release/2.3 and master branches.

commit a91a2d6ad7b139ec78d61c8616b8447847e9ecc6 (release/2.3) commit 5b17803ebbb0989cf66033387dfa1ae7cb41bb25 (master)

Author: James Yonan
Date:   Thu May 8 16:50:36 2014 -0600
     Fixed some compile issues with show_library_versions()

     Signed-off-by: James Yonan <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8711
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering