Skip to contentSkip to conversation

Change in openvpn[master]: Replace strtok with strtok_r

Openvpn-devel In review plaisthos (Code Review) 4 participants 14 messages May 16 – Jul 15 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1778963232000.I70560efd113308b7377424127eb2c1da4266371a@gerrit.openvpn.net

#1 lore raw

plaisthos has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

---
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c

4 files changed, 15 insertions(+), 10 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/1

src/openvpn/options_util.c +3 -2
index 47fe0bc..fbc64fa 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..7f0af3f 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..33f33ef 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..8c6e2bc 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
Signature · 11 lines
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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

#2 lore raw
In reply to a message not in the archive

plaisthos has uploaded a new patch set (#2). ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

---
M CMakeLists.txt
M configure.ac
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c

8 files changed, 123 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/2

CMakeLists.txt +1 -0
index 715d02c..dde7dc7 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..fbc64fa 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..7f0af3f 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..33f33ef 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..8c6e2bc 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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

#3 lore raw
In reply to a message not in the archive

plaisthos has uploaded a new patch set (#3). ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

---
M CMakeLists.txt
M configure.ac
M src/compat/Makefile.am
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c
M tests/unit_tests/openvpn/Makefile.am

10 files changed, 130 insertions(+), 13 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/3

CMakeLists.txt +4 -1
index 715d02c..6ab7c10 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -413,6 +414,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -733,7 +735,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
-            )
+            src/compat/compat-strsep.c
+        )
 
         add_library_deps(${test_name})
         target_link_libraries(${test_name} PUBLIC ${CMOCKA_LIBRARIES})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..fbc64fa 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..7f0af3f 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..33f33ef 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..8c6e2bc 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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

#4 lore raw
In reply to a message not in the archive

plaisthos has uploaded a new patch set (#4). ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

---
M CMakeLists.txt
M configure.ac
M src/compat/Makefile.am
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c
M tests/unit_tests/openvpn/Makefile.am

10 files changed, 130 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/4

CMakeLists.txt +4 -0
index 715d02c..ceafbb4 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -413,6 +414,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -733,6 +735,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
+            src/compat/compat-strsep.c
+            src/compat/compat-strtok_r.c
             )
 
         add_library_deps(${test_name})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..fbc64fa 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..7f0af3f 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..33f33ef 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..8c6e2bc 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Patch Set 4:

(1 comment)

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/1679/comment/0fcc165a_f8562a96?usp=email :
PS4, Line 51: char *lasts;
The Linux man page for strtok_r warns "On some implementations, *saveptr is required to be NULL on the first call to strtok_r() that is being used to parse str." So maybe we should initialize it to NULL instead of giving it uninitialized?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Comment-Date: Wed, 20 May 2026 15:48:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

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

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

plaisthos has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Patch Set 4:

(1 comment)

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/1679/comment/9ddf5d84_137b19de?usp=email :
PS4, Line 51: char *lasts;

Quoted 1 line

The Linux man page for strtok_r warns "On some implementations, *saveptr is required to be NULL on t […]

Sounds good. Will amend the patch to do that.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]>
Gerrit-Comment-Date: Wed, 20 May 2026 16:01:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]>

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

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

plaisthos has uploaded a new patch set (#5). ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

---
M CMakeLists.txt
M configure.ac
M src/compat/Makefile.am
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c
M tests/unit_tests/openvpn/Makefile.am

10 files changed, 130 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/5

CMakeLists.txt +4 -0
index 715d02c..ceafbb4 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -413,6 +414,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -733,6 +735,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
+            src/compat/compat-strsep.c
+            src/compat/compat-strtok_r.c
             )
 
         add_library_deps(${test_name})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..d72ea25c 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts = NULL;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..07caf08 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts = NULL;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..baf5a95 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts = NULL;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts = NULL;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..1db7f55 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts = NULL;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]>

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

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

plaisthos has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Patch Set 5:

(1 comment)

File src/openvpn/options_util.c:

http://gerrit.openvpn.net/c/openvpn/+/1679/comment/be9f75b1_d2478461?usp=email :
PS4, Line 51: char *lasts;

Quoted 1 line

Sounds good. Will amend the patch to do that.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]>
Gerrit-Comment-Date: Wed, 20 May 2026 16:18:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]>
Comment-In-Reply-To: flichtenheld <[email protected]>

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

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Patch Set 5:

(1 comment)

Patchset:

PS5:
LGTM. However, I have not reviewed the compat implementation.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-CC: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Comment-Date: Wed, 20 May 2026 16:33:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

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

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Patch Set 5: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Comment-Date: Wed, 20 May 2026 16:33:35 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

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

#11 lore raw

PATCH v5 1/1 Replace strtok with strtok_r

In reply to a message not in the archive

From: Arne Schwabe <[email protected]>

This dos not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1679
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1679
This mail reflects revision 5 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]>

CMakeLists.txt +4 -0
index 715d02c..ceafbb4 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -413,6 +414,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -733,6 +735,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
+            src/compat/compat-strsep.c
+            src/compat/compat-strtok_r.c
             )
 
         add_library_deps(${test_name})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..d72ea25c 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts = NULL;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..07caf08 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts = NULL;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..baf5a95 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts = NULL;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts = NULL;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 0804d2d..1db7f55 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts = NULL;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

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

Acked-by Frank Lichtenheld on v5 1/1
#12 lore raw

[Openvpn-devel] [PATCH applied] Re: Replace strtok with strtok_r

"Code proofing for the future", or so. After a bit of discussion it was decided that this only impacts -Werror on Android, and the Android app is only built from master, so it does not need to go to release/2.7 ("for now").

Passed all BB tests and a full t_server run, plus good stare-at-code and a "make distcheck" (= new files added tend to be forgotten...)

Your patch has been applied to the master branch.

commit 27df276eabdf87ad97ab88e8e84cc53d2bbc59c8 (master)

Author: Arne Schwabe
Date:   Wed Jul 8 17:31:07 2026 +0200

Replace strtok with strtok_r

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1679
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37538.html

--
kind regards,

Gert Doering

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

#13 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#6) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This does not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1679
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37538.html

---
M CMakeLists.txt
M configure.ac
M src/compat/Makefile.am
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c
M tests/unit_tests/openvpn/Makefile.am

10 files changed, 130 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1679/6

CMakeLists.txt +4 -0
index 23541a5d..7473f15 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -423,6 +424,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -743,6 +745,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
+            src/compat/compat-strsep.c
+            src/compat/compat-strtok_r.c
             )
 
         add_library_deps(${test_name})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..d72ea25c 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts = NULL;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..07caf08 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts = NULL;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..baf5a95 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts = NULL;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts = NULL;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 9197adf..162f68f 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts = NULL;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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

#14 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email )

Change subject: Replace strtok with strtok_r
......................................................................

Replace strtok with strtok_r

This does not change anything in our source code but makes compiling with newer Android NDKs (version 30 pre release) -Werror safe again as it has started throwing warning on this.

The compat version is taken from current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok.c and reformatted to our clang standard.

Change-Id I70560efd113308b7377424127eb2c1da4266371a

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1679
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37538.html

---
M CMakeLists.txt
M configure.ac
M src/compat/Makefile.am
A src/compat/compat-strtok_r.c
M src/compat/compat.h
M src/openvpn/options_util.c
M src/openvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_verify.c
M tests/unit_tests/openvpn/Makefile.am

10 files changed, 130 insertions(+), 12 deletions(-)
CMakeLists.txt +4 -0
index 23541a5d..7473f15 100644
@@ -248,6 +248,7 @@
 check_symbol_exists(chsize io.h HAVE_CHSIZE)
 check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT)
 check_symbol_exists(strsep string.h HAVE_STRSEP)
+check_symbol_exists(strtok_r string.h HAVE_STRTOK_R)
 
 # Some OS (e.g. FreeBSD) need some basic headers to allow
 # including network headers
@@ -423,6 +424,7 @@
     src/compat/compat-dirname.c
     src/compat/compat-gettimeofday.c
     src/compat/compat-strsep.c
+    src/compat/compat-strtok_r.c
     src/openvpn/argv.c
     src/openvpn/argv.h
     src/openvpn/base64.c
@@ -743,6 +745,8 @@
             src/openvpn/platform.c
             src/openvpn/win32-util.c
             src/compat/compat-gettimeofday.c
+            src/compat/compat-strsep.c
+            src/compat/compat-strtok_r.c
             )
 
         add_library_deps(${test_name})
configure.ac +1 -1
index e19d651..188f8fa 100644
@@ -568,7 +568,7 @@
 	setgroups flock gettimeofday \
 	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname \
-	epoll_create strsep \
+	epoll_create strsep strtok_r \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +2 -1
index 69b2990..22867b3 100644
@@ -20,4 +20,5 @@
 	compat-basename.c \
 	compat-gettimeofday.c \
 	compat-daemon.c \
-	compat-strsep.c
\ No newline at end of file
+	compat-strsep.c \
+	compat-strtok_r.c
\ No newline at end of file
src/compat/compat-strtok_r.c new file +101 -0

102 lines not on this page · raw message

src/compat/compat.h +5 -0
index 6532b86..9e6f95c 100644
@@ -61,4 +61,9 @@
 
 #endif
 
+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim, char **last);
+#endif
+
 #endif /* COMPAT_H */
src/openvpn/options_util.c +3 -2
index 47fe0bc..d72ea25c 100644
@@ -48,7 +48,8 @@
         message = strstr(reason, "]") + 1;
         /* null terminate the substring to only looks for flags between [ and ] */
         *endofflags = '\x00';
-        const char *token = strtok(m, "[,");
+        char *lasts = NULL;
+        const char *token = strtok_r(m, "[,", &lasts);
         while (token)
         {
             if (!strncmp(token, "backoff ", strlen("backoff ")))
@@ -81,7 +82,7 @@
             {
                 msg(D_PUSH_ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
             }
-            token = strtok(NULL, "[,");
+            token = strtok_r(NULL, "[,", &lasts);
         }
     }
 
src/openvpn/ssl_mbedtls.c +3 -2
index 8a0f7d2..07caf08 100644
@@ -318,9 +318,10 @@
 
     /* Parse allowed ciphers, getting IDs */
     int i = 0;
+    char *lasts = NULL;
     tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL);
 
-    token = strtok(tmp_ciphers, ":");
+    token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         ctx->allowed_ciphers[i] = mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(token));
@@ -328,7 +329,7 @@
         {
             i++;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 }
src/openvpn/ssl_ncp.c +6 -4
index 649665a..baf5a95 100644
@@ -100,7 +100,8 @@
     struct buffer new_list = alloc_buf(MAX_NCP_CIPHERS_LENGTH);
 
     char *const tmp_ciphers = string_alloc(list, NULL);
-    const char *token = strtok(tmp_ciphers, ":");
+    char *lasts = NULL;
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         /*
@@ -174,7 +175,7 @@
                 buf_puts(&new_list, ovpn_cipher_name);
             }
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
 
 
@@ -207,15 +208,16 @@
 {
     char *tmp_ciphers = string_alloc(list, NULL);
     char *tmp_ciphers_orig = tmp_ciphers;
+    char *lasts = NULL;
 
-    const char *token = strtok(tmp_ciphers, ":");
+    const char *token = strtok_r(tmp_ciphers, ":", &lasts);
     while (token)
     {
         if (0 == strcmp(token, item))
         {
             break;
         }
-        token = strtok(NULL, ":");
+        token = strtok_r(NULL, ":", &lasts);
     }
     free(tmp_ciphers_orig);
 
src/openvpn/ssl_verify.c +3 -2
index 9197adf..162f68f 100644
@@ -868,7 +868,8 @@
         return false;
     }
 
-    const char *client_method = strtok(iv_sso, ",");
+    char *lasts = NULL;
+    const char *client_method = strtok_r(iv_sso, ",", &lasts);
     bool supported = false;
 
     while (client_method)
@@ -878,7 +879,7 @@
             supported = true;
             break;
         }
-        client_method = strtok(NULL, ",");
+        client_method = strtok_r(NULL, ",", &lasts);
     }
 
     gc_free(&gc);
tests/unit_tests/openvpn/Makefile.am +2 -0
index 1128eb4..d861ef9 100644
@@ -107,6 +107,7 @@
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/crypto.c \
 	$(top_srcdir)/src/openvpn/cryptoapi.c \
 	$(top_srcdir)/src/openvpn/crypto_epoch.c \
@@ -345,6 +346,7 @@
 	$(top_srcdir)/src/openvpn/platform.c \
 	$(top_srcdir)/src/openvpn/win32-util.c \
 	$(top_srcdir)/src/compat/compat-strsep.c \
+	$(top_srcdir)/src/compat/compat-strtok_r.c \
 	$(top_srcdir)/src/openvpn/ssl_util.c
 
 mbuf_testdriver_CFLAGS  = \

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1679?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a
Gerrit-Change-Number: 1679
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

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