Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7F4AC44508 for ; Wed, 15 Jul 2026 17:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Type:Cc:Reply-To:From: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:Message-ID:References:In-Reply-To:To:Date:Sender: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mXKEnPNLuKNFPIIEx/3+FFLt7y/ZIlMVXMutuYEzMIU=; b=MraBlYPpfoTdiW1ah2LjjeJZt+ sxMTVloo/U0cm49RB79JckEoEpJPXG3vzYVuludXcZg5WfSoDrRWchIB61aMnIvbFo9oK2OFOzDZi EjD1pgVB23WI420vMRPxQtrCvaiWb421fc0ujDu8dAqC1Ihut7krEGXKyhuYJtokYZag=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wk3YU-00032O-Ke; Wed, 15 Jul 2026 17:37:59 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wk3YS-00032F-Tc for openvpn-devel@lists.sourceforge.net; Wed, 15 Jul 2026 17:37:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:Subject:References:In-Reply-To:List-Unsubscribe:List-Id: Cc:To:Date:From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Help:List-Subscribe :List-Post:List-Owner:List-Archive; bh=lEz3VzAkgQqumm3mdaR3FXd6I82hFoo+OU0WkVMKd6s=; b=E2Jz2gYx+fxkuX5KOeO8/tNGIp 8mLmnq5qq+Tawe9B/tjVInQh1E4jeawmKU/X23poK5FhS8UUEkrqMA3DYSig03ZQQzIa58Xx/QCnc q8WaabenW9RxF0S72Ku0ZTOQbGd+erR/ZfRuR3enawfQq8F720S8g7SFhNBK3U5cP98k=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: Subject:References:In-Reply-To:List-Unsubscribe:List-Id:Cc:To:Date:From: Sender:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=lEz3VzAkgQqumm3mdaR3FXd6I82hFoo+OU0WkVMKd6s=; b=F gUoVJ5ekVi9k5Mkuq0nV8BFDYqWki5098UdbKdJwi7HRjwfF6eUdXn1BzOXS6imn2V6QGbd8U5b/j j+A4LeTrJGrSgtYX4ISsPKRMnSGumPZIVd5kb0M40AxGMR0mih+Xtmt74QALoYjZAFlcVaIJNmliu DUCG40DO3oad//do=; Received: from mail-wm1-f43.google.com ([209.85.128.43]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1wk3YL-0007bi-S6 for openvpn-devel@lists.sourceforge.net; Wed, 15 Jul 2026 17:37:56 +0000 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-493ece78b0cso40381625e9.0 for ; Wed, 15 Jul 2026 10:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1784137058; x=1784741858; darn=lists.sourceforge.net; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references:in-reply-to:list-unsubscribe:list-id :auto-submitted:cc:to:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=lEz3VzAkgQqumm3mdaR3FXd6I82hFoo+OU0WkVMKd6s=; b=Gm/2jfizN4/4hZ+1PoGWTQtMme1jET7VdGu8we7q+myVJ4npTrgC5Nd8pzQWIxzsZY rDRF9WLFTgLbQCxYZ2EXdc4ZUOqrzwNZ//n/knjnNVOsS2gLPRnZUEptVkIQxrglxMel p7Mpwxcpw2w14ph5++zaFux2P40Rqb9gqykHoRtz/uTxQFpZ5f32/uAB7Fsj4Z2pACfN OTULpDq42/EfblHfNzHGHeQsU7rnd2aPhfig77/tOkUr9GlZNhNQ5pI+PNAKQHyyAPm8 QpTc2ufxzDFNoJucKkw2j/V5NHjsph1Gz+pkJbONfHSF+Gy07mcdZHZRJXzpjnwM5llU 5Bvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784137058; x=1784741858; h=content-type:user-agent:content-disposition :content-transfer-encoding:mime-version:message-id:reply-to:subject :thread-index:references:in-reply-to:list-unsubscribe:list-id :auto-submitted:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=lEz3VzAkgQqumm3mdaR3FXd6I82hFoo+OU0WkVMKd6s=; b=FxKqpPrO9VIBQ64qVK/kutxlFnWRmIQGtyNidIcE9BcGoAw9qMZA0a6LsXu/O7sOmb ud6BKJKxWZkv6C1O7HtuRQEQ1CfwS3fE428TA+WRzlnL6KQoi9TgManT1bYQzmWbpKTW gSIkHVj0QOeL4b+/xmTZtYmfvNDqNGqYkYuw2vxBE4uQhCsJuDibqN21ulhneXPBtMwW V49GNJi+w0pErMXsNAqhDKPCAZnJQqYFOBrEc5KgTKhQ/wKitL+5DIyV/aUi1uRCsynV mR6YdYeFPHZqQchrySiAonvOKu43thnULOUl8uNI7q8T1rVPR+86Iux9LGtZXD0kKbgs MglA== X-Forwarded-Encrypted: i=1; AHgh+Rq4wOaJUv6nGX6lOrZ5LK4iP1SHdGSXUPFdeo/lhdg0kufMDHWcgZhCGhJQtSr7/az11HvH5mvsIZSDw3oQ@lists.sourceforge.net X-Gm-Message-State: AOJu0Yy5uboDxqnybdRA7bVMXrSHmYLsCG1Pzsj9TJ4l5EBWZ5CpCPZ8 iL93xDW1A23ZJcwnhUbj+jKt2k19pEGUl5rqlazUGqaK2EVowyrdGzzLn3UugyRQD4sE/OlFXP/ n4y+c/ycAVOGDA5obFbCuqCj4sfPAg0b9tiOa8ubywv+QxVDjwbtLjGwQIknHfrvAmNyVOdpBWs sx4z/Nqg== X-Gm-Gg: AfdE7cnabZgauBwrBMJGc690YcG5XZBwxVGCIJvJTpT8hTLKPZFLFlIJb1co2uIQMWF 3zDNrP+XSzA6wglHdZd0CIaB9JyO0NueB5OmFjK8cgYqeIeL1arRYmLFQ1M67kLhwbDlgbO5r/m dJ5t7gNiMyeKnMA3JDG7AMfR6wGsL7azxRqtV/qZGkAtKbloIuMaRmc9HnZDiE7PZ57Ww4jAmXX V3nnlEPD+H0jy4Ya9/b0lLdbRMiW5e/J5gCYRVO3d6OxSdabTIhDeLsqjitotVMSlE10mCQVi3h 22OxHoTOjgPzOkK2JYKK6pKJelmjg0NdVhvjsfPb6lXP/NFxy6677XhkSBqoFa5Le7pdi4rmZEQ drNHRDTQi60Zsg0AiIymeLpx3jjIsh9xoONhe5rW2lGcpbe6drDCijnW/9QKNPhwzGQmlD1ksRr 38GzF9GVCqTBYohz5DFhKcCP5ovmSssr4S6ncm0gFwyKVwJeZygHCPR2CjxZH7yXVOEGZTWYbM5 cIa7fXvZoKM74Wjb4K/0DLy1t1ragtlGcgH0ssbk7sehe5wUjj+OcIiA07pqAva3enQWXXifHQE LPs= X-Received: by 2002:a05:600c:19d0:b0:492:6efc:7c60 with SMTP id 5b1f17b1804b1-49518308220mr103313765e9.28.1784137058011; Wed, 15 Jul 2026 10:37:38 -0700 (PDT) Received: from ip-10-18-1-162.eu-central-1.compute.internal (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f4635a935sm17751036f8f.11.2026.07.15.10.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 10:37:37 -0700 (PDT) X-Google-Original-From: "cron2 (Code Review)" Date: Wed, 15 Jul 2026 17:37:36 +0000 To: plaisthos Auto-Submitted: auto-generated X-Gerrit-MessageType: merged X-Gerrit-PatchSet: 6 X-Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a X-Gerrit-Change-Number: 1679 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 27df276eabdf87ad97ab88e8e84cc53d2bbc59c8 In-Reply-To: References: Thread-Index: PGdlcnJpdC4xNzc4OTYzMjMyMDAwLkk3MDU2MGVmZDExMzMwOGI3Mzc3NDI0MTI3ZWIyYzFkYTQyNjYzNzFhQGdlcnJpdC5vcGVudnBuLm5ldD4= Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.11.5 X-Headers-End: 1wk3YL-0007bi-S6 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Replace strtok with strtok_r X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "cron2 \(Code Review\) via Openvpn-devel" Reply-To: gert@greenie.muc.de, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: "cron2 \(Code Review\)" , openvpn-devel Content-Type: multipart/mixed; boundary="===============1318835698950892666==" Errors-To: openvpn-devel-bounces@lists.sourceforge.net --===============1318835698950892666== Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="wppluVeuX6o="; charset=UTF-8 --wppluVeuX6o= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable cron2 has submitted this change=2E ( http://gerrit=2Eopenvpn=2Enet/c/openvp= n/+/1679?usp=3Demail ) Change subject: Replace strtok with strtok_r =2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E= =2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E=2E Replace strtok with= strtok_r This does not change anything in our source code but makes compi= ling with newer Android NDKs (version 30 pre release) -Werror safe again as= it has started throwing warning on this=2E The compat version is taken fr= om current FreeBSD (commit dc36d6f9bb1) src/lib/libc/string/strtok=2Ec and = reformatted to our clang standard=2E Change-Id: I70560efd113308b7377424127= eb2c1da4266371a Signed-off-by: Arne Schwabe Acked-by: = Frank Lichtenheld Gerrit URL: https://gerrit=2Eop= envpn=2Enet/c/openvpn/+/1679 Message-Id: <20260708153107=2E60809-1-frank@li= chtenheld=2Ecom> URL: https://www=2Email-archive=2Ecom/openvpn-devel@lists= =2Esourceforge=2Enet/msg37538=2Ehtml Signed-off-by: Gert Doering --- M CMakeLists=2Etxt M configure=2Eac M src/compat/Makefi= le=2Eam A src/compat/compat-strtok_r=2Ec M src/compat/compat=2Eh M src/open= vpn/options_util=2Ec M src/openvpn/ssl_mbedtls=2Ec M src/openvpn/ssl_ncp=2E= c M src/openvpn/ssl_verify=2Ec M tests/unit_tests/openvpn/Makefile=2Eam 10 = files changed, 130 insertions(+), 12 deletions(-) diff --git a/CMakeLis= ts=2Etxt b/CMakeLists=2Etxt index 23541a5d=2E=2E7473f15 100644 --- a/CMakeL= ists=2Etxt +++ b/CMakeLists=2Etxt @@ -248,6 +248,7 @@ check_symbol_exists(= chsize io=2Eh HAVE_CHSIZE) check_symbol_exists(getrlimit sys/resource=2Eh = HAVE_GETRLIMIT) check_symbol_exists(strsep string=2Eh HAVE_STRSEP) +check_= symbol_exists(strtok_r string=2Eh HAVE_STRTOK_R) # Some OS (e=2Eg=2E Fre= eBSD) need some basic headers to allow # including network headers @@ -423= ,6 +424,7 @@ src/compat/compat-dirname=2Ec src/compat/compat-gett= imeofday=2Ec src/compat/compat-strsep=2Ec + src/compat/compat-strto= k_r=2Ec src/openvpn/argv=2Ec src/openvpn/argv=2Eh src/openvp= n/base64=2Ec @@ -743,6 +745,8 @@ src/openvpn/platform=2Ec = src/openvpn/win32-util=2Ec src/compat/compat-gettimeo= fday=2Ec + src/compat/compat-strsep=2Ec + src/compat/= compat-strtok_r=2Ec ) add_library_deps(${test_name}= ) diff --git a/configure=2Eac b/configure=2Eac index e19d651=2E=2E188f8fa 1= 00644 --- a/configure=2Eac +++ b/configure=2Eac @@ -568,7 +568,7 @@ setgr= oups flock gettimeofday \ setsid chdir \ chsize ftruncate execve getpee= reid basename dirname \ - epoll_create strsep \ + epoll_create strsep strto= k_r \ ]) AC_CHECK_LIB( diff --git a/src/compat/Makefile=2Eam b/src/comp= at/Makefile=2Eam index 69b2990=2E=2E22867b3 100644 --- a/src/compat/Makefil= e=2Eam +++ b/src/compat/Makefile=2Eam @@ -20,4 +20,5 @@ compat-basename= =2Ec \ compat-gettimeofday=2Ec \ compat-daemon=2Ec \ - compat-strsep=2E= c \ No newline at end of file + compat-strsep=2Ec \ + compat-strtok_r=2Ec \= No newline at end of file diff --git a/src/compat/compat-strtok_r=2Ec b/sr= c/compat/compat-strtok_r=2Ec new file mode 100644 index 0000000=2E=2Edebcdd= 3 --- /dev/null +++ b/src/compat/compat-strtok_r=2Ec @@ -0,0 +1,101 @@ +/*-= + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1998 Softw= eyr LLC=2E All rights reserved=2E + * + * strtok_r, from Berkeley strtok += * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 19= 88, 1993 + * The Regents of the University of California=2E All right= s reserved=2E + * + * Redistribution and use in source and binary forms, wi= th or without + * modification, are permitted provided that the following c= onditions + * are met: + * 1=2E Redistributions of source code must retain = the above copyright + * notices, this list of conditions and the followi= ng disclaimer=2E + * 2=2E Redistributions in binary form must reproduce the= above copyright + * notices, this list of conditions and the following = disclaimer in the + * documentation and/or other materials provided with= the distribution=2E + * 3=2E Neither the name of the University nor the na= mes of its contributors + * may be used to endorse or promote products d= erived from this software + * without specific prior written permission= =2E + * + * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONT= RIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BU= T NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS= FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED=2E IN NO EVENT SHALL SOFTWEYR= LLC, THE + * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, = INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BU= T NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF = USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON = ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT= (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE = OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE=2E = + */ +#ifdef HAVE_CONFIG_H +#include "config=2Eh" +#endif + +#ifndef HAVE_S= TRTOK_R +#include + +char * +strtok_r(char *s, const char *del= im, char **last) +{ + char *spanp, *tok; + int c, sc; + + if (s = =3D=3D NULL && (s =3D *last) =3D=3D NULL) + { + return (NULL); + = } + +/* + * Skip (span) leading delimiters (s +=3D strspn(s, delim), sor= t of)=2E + */ +cont: + c =3D *s++; + for (spanp =3D (char *)delim; (s= c =3D *spanp++) !=3D 0;) + { + if (c =3D=3D sc) + { + = goto cont; + } + } + + if (c =3D=3D 0) + { /* no non= -delimiter characters */ + *last =3D NULL; + return (NULL); += } + tok =3D s - 1; + + /* + * Scan token (scan for delimiters= : s +=3D strcspn(s, delim), sort of)=2E + * Note that delim must have o= ne NUL; we stop if we see that, too=2E + */ + for (;;) + { + = c =3D *s++; + spanp =3D (char *)delim; + do + { + = if ((sc =3D *spanp++) =3D=3D c) + { + i= f (c =3D=3D 0) + { + s =3D NULL; + = } + else + { + s[= -1] =3D '\0'; + } + *last =3D s; + = return (tok); + } + } while (sc !=3D 0); + } + = /* NOTREACHED */ +} +#endif \ No newline at end of file diff --git a/src/c= ompat/compat=2Eh b/src/compat/compat=2Eh index 6532b86=2E=2E9e6f95c 100644 = --- a/src/compat/compat=2Eh +++ b/src/compat/compat=2Eh @@ -61,4 +61,9 @@ = #endif +#ifndef HAVE_STRTOK_R +char * +strtok_r(char *s, const char *de= lim, char **last); +#endif + #endif /* COMPAT_H */ diff --git a/src/openvp= n/options_util=2Ec b/src/openvpn/options_util=2Ec index 47fe0bc=2E=2Ed72ea2= 5c 100644 --- a/src/openvpn/options_util=2Ec +++ b/src/openvpn/options_util= =2Ec @@ -48,7 +48,8 @@ message =3D strstr(reason, "]") + 1; = /* null terminate the substring to only looks for flags between [ and ] = */ *endofflags =3D '\x00'; - const char *token =3D strtok(m= , "[,"); + char *lasts =3D NULL; + const char *token =3D strt= ok_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 =3D strtok(NULL, "[,")= ; + token =3D strtok_r(NULL, "[,", &lasts); } } = diff --git a/src/openvpn/ssl_mbedtls=2Ec b/src/openvpn/ssl_mbedtls=2Ec inde= x 8a0f7d2=2E=2E07caf08 100644 --- a/src/openvpn/ssl_mbedtls=2Ec +++ b/src/o= penvpn/ssl_mbedtls=2Ec @@ -318,9 +318,10 @@ /* Parse allowed ciphers= , getting IDs */ int i =3D 0; + char *lasts =3D NULL; tmp_ciph= ers_orig =3D tmp_ciphers =3D string_alloc(ciphers, NULL); - token =3D = strtok(tmp_ciphers, ":"); + token =3D strtok_r(tmp_ciphers, ":", &lasts)= ; while (token) { ctx->allowed_ciphers[i] =3D mbedtls_ss= l_get_ciphersuite_id(tls_translate_cipher_name(token)); @@ -328,7 +329,7 @@= { i++; } - token =3D strtok(NULL, ":= "); + token =3D strtok_r(NULL, ":", &lasts); } free(tmp_ci= phers_orig); } diff --git a/src/openvpn/ssl_ncp=2Ec b/src/openvpn/ssl_ncp= =2Ec index 649665a=2E=2Ebaf5a95 100644 --- a/src/openvpn/ssl_ncp=2Ec +++ b/= src/openvpn/ssl_ncp=2Ec @@ -100,7 +100,8 @@ struct buffer new_list =3D= alloc_buf(MAX_NCP_CIPHERS_LENGTH); char *const tmp_ciphers =3D stri= ng_alloc(list, NULL); - const char *token =3D strtok(tmp_ciphers, ":"); = + char *lasts =3D NULL; + const char *token =3D strtok_r(tmp_ciphers,= ":", &lasts); while (token) { /* @@ -174,7 +175,7 @@ = buf_puts(&new_list, ovpn_cipher_name); } = } - token =3D strtok(NULL, ":"); + token =3D strtok_r(NULL= , ":", &lasts); } @@ -207,15 +208,16 @@ { char *tmp_ciphers = =3D string_alloc(list, NULL); char *tmp_ciphers_orig =3D tmp_ciphers; = + char *lasts =3D NULL; - const char *token =3D strtok(tmp_ciphers,= ":"); + const char *token =3D strtok_r(tmp_ciphers, ":", &lasts); = while (token) { if (0 =3D=3D strcmp(token, item)) { = break; } - token =3D strtok(NULL, ":"); + = token =3D strtok_r(NULL, ":", &lasts); } free(tmp_ciphers_orig= ); diff --git a/src/openvpn/ssl_verify=2Ec b/src/openvpn/ssl_verify=2Ec i= ndex 9197adf=2E=2E162f68f 100644 --- a/src/openvpn/ssl_verify=2Ec +++ b/src= /openvpn/ssl_verify=2Ec @@ -868,7 +868,8 @@ return false; } = - const char *client_method =3D strtok(iv_sso, ","); + char *lasts = =3D NULL; + const char *client_method =3D strtok_r(iv_sso, ",", &lasts);= bool supported =3D false; while (client_method) @@ -878,7 +879= ,7 @@ supported =3D true; break; } - = client_method =3D strtok(NULL, ","); + client_method =3D strtok_= r(NULL, ",", &lasts); } gc_free(&gc); diff --git a/tests/unit_t= ests/openvpn/Makefile=2Eam b/tests/unit_tests/openvpn/Makefile=2Eam index 1= 128eb4=2E=2Ed861ef9 100644 --- a/tests/unit_tests/openvpn/Makefile=2Eam +++= b/tests/unit_tests/openvpn/Makefile=2Eam @@ -107,6 +107,7 @@ $(top_srcdi= r)/src/openvpn/base64=2Ec \ $(top_srcdir)/src/openvpn/buffer=2Ec \ $(to= p_srcdir)/src/compat/compat-strsep=2Ec \ + $(top_srcdir)/src/compat/compat-= strtok_r=2Ec \ $(top_srcdir)/src/openvpn/crypto=2Ec \ $(top_srcdir)/src= /openvpn/cryptoapi=2Ec \ $(top_srcdir)/src/openvpn/crypto_epoch=2Ec \ @@ = -345,6 +346,7 @@ $(top_srcdir)/src/openvpn/platform=2Ec \ $(top_srcdir)= /src/openvpn/win32-util=2Ec \ $(top_srcdir)/src/compat/compat-strsep=2Ec = \ + $(top_srcdir)/src/compat/compat-strtok_r=2Ec \ $(top_srcdir)/src/open= vpn/ssl_util=2Ec mbuf_testdriver_CFLAGS =3D \ -- To view, visit http:= //gerrit=2Eopenvpn=2Enet/c/openvpn/+/1679?usp=3Demail To unsubscribe, or fo= r help writing mail filters, visit http://gerrit=2Eopenvpn=2Enet/settings?u= sp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branc= h: master Gerrit-Change-Id: I70560efd113308b7377424127eb2c1da4266371a Gerri= t-Change-Number: 1679 Gerrit-PatchSet: 6 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld = Gerrit-CC: openvpn-devel --wppluVeuX6o= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change=2E

View Change

Replace strtok with strtok_r

This d= oes not change anything in our source code but makes compiling
with newe= r Android NDKs (version 30 pre release) -Werror safe again
as it has sta= rted throwing warning on this=2E

The compat version is taken from cu= rrent FreeBSD (commit dc36d6f9bb1)
src/lib/libc/string/strtok=2Ec and re= formatted to our clang standard=2E

Change-Id: I70560efd113308b737742= 4127eb2c1da4266371a
Signed-off-by: Arne Schwabe <arne@rfc2549=2Eorg&g= t;
Acked-by: Frank Lichtenheld <frank@lichtenheld=2Ecom>
Gerrit= URL: https://gerrit=2Eopenvpn=2Enet/c/openvpn/+/1679
Message-Id: <20= 260708153107=2E60809-1-frank@lichtenheld=2Ecom>
URL: https://www=2Ema= il-archive=2Ecom/openvpn-devel@lists=2Esourceforge=2Enet/msg37538=2EhtmlSigned-off-by: Gert Doering <gert@greenie=2Emuc=2Ede>
---
M CM= akeLists=2Etxt
M configure=2Eac
M src/compat/Makefile=2Eam
A src/c= ompat/compat-strtok_r=2Ec
M src/compat/compat=2Eh
M src/openvpn/optio= ns_util=2Ec
M src/openvpn/ssl_mbedtls=2Ec
M src/openvpn/ssl_ncp=2EcM src/openvpn/ssl_verify=2Ec
M tests/unit_tests/openvpn/Makefile=2Eam<= br>10 files changed, 130 insertions(+), 12 deletions(-)

di=
ff --git a/CMakeLists=2Etxt b/CMakeLists=2Etxt
index 23541a= 5d=2E=2E7473f15 100644
--- a/CMakeLists=2Etxt
+++ b/CMakeLists=2Etxt
@@ -248,6 +248,7 @@
check_symbol_exists(chsize io=2Eh HAVE_CHSIZE)
check_s= ymbol_exists(getrlimit sys/resource=2Eh HAVE_GETRLIMIT)
ch= eck_symbol_exists(strsep string=2Eh HAVE_STRSEP)
+check_symbol_exists(strtok_r string=2Eh HAVE_S= TRTOK_R)

# Some OS (e=2Eg=2E FreeBSD) ne= ed some basic headers to allow
# including network headers=
@@ -423,6 +424,7 @@
src/compat/compat= -dirname=2Ec
src/compat/compat-gettimeofday=2Ec=
src/compat/compat-strsep=2Ec
+ src/compat/compat-strtok_r=2Ec
= src/openvpn/argv=2Ec
src/openvpn/argv=2Eh<= br> src/openvpn/base64=2Ec
@@ -743,6 +745,8 @@
src/openvpn/platform=2Ec
= src/openvpn/win32-util=2Ec
src/compat/co= mpat-gettimeofday=2Ec
+ src/compat/compat-strsep=2Ec
+ src/compat/compat-strtok_r=2Ec )

add_librar= y_deps(${test_name})
diff --git a/configure=2Eac b/configur= e=2Eac
index e19d651=2E=2E188f8fa 100644
--= - a/configure=2Eac
+++ b/configure=2Eac
@@ = -568,7 +568,7 @@
setgroups flock gettimeofday \ setsid chdir \
chsize ftruncate execve getpeerei= d basename dirname \
- = epoll_create strsep \
+ epoll_create strsep strtok_r \
])

AC_CHECK_LIB(
diff --git a/src/compat/Makefil= e=2Eam b/src/compat/Makefile=2Eam
index 69b2990=2E=2E22867b= 3 100644
--- a/src/compat/Makefile=2Eam
+++= b/src/compat/Makefile=2Eam
@@ -20,4 +20,5 @@
compat-basename=2Ec \
compat-gettimeofday=2Ec \
compat-daemon=2Ec \
- compat-strsep=2Ec
\ No newline at end of file<= /span>
+ compat-strsep=2Ec \=
+ compat-strtok_r=2E= c
\ No newline at end of file
diff --git a/= src/compat/compat-strtok_r=2Ec b/src/compat/compat-strtok_r=2Ec
<= span>new file mode 100644

index 0000000=2E=2Edebcdd3=
--- /dev/null
+++ b/src/compat/compat-strtok_r=2E= c
@@ -0,0 +1,101 @@
+/*-
+= * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1998 Softweyr LLC=2E All rights reserved=2E+ *
+ * strtok_r, from Berkeley strtok
+ * Oct 13, 1998 by Wes Peters &l= t;wes@softweyr=2Ecom>

+ *
+ * Copyright= (c) 1988, 1993
+ * = The Regents of the University of California=2E All rights reserved=2E<= /span>
+ *
+ * Redistribution and use in source a= nd binary forms, with or without
+ * modification, are permitted provided that the following con= ditions
+ * are met:<= /span>
+ * 1=2E Redistributi= ons of source code must retain the above copyright
+ * notices, this list of conditions and t= he following disclaimer=2E
+ * 2=2E Redistributions in binary form must reproduce the above copy= right
+ * notices,= this list of conditions and the following disclaimer in the
+ * documentation and/or other m= aterials provided with the distribution=2E

+ * 3=2E Neither the name of the University nor the n= ames of its contributors
+ * may be used to endorse or promote products derived from this sof= tware
+ * without = specific prior written permission=2E
+ *
+= * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS<= /span>
+ * ``AS IS''= AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIE= S OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED=2E IN NO EVENT SHA= LL SOFTWEYR LLC, THE
= + * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL= ,
+ * SPECIAL, EXEMPL= ARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOOD= S OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O= N ANY THEORY OF
+ * L= IABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<= br>+ * NEGLIGENCE OR OTHERWISE)= ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF S= UCH DAMAGE=2E
+ */
+#ifdef HAVE_CONFIG_H
+#include "config= =2Eh"
+#endif
+
+#ifndef HAVE_STRTOK_R
+#include <string=2Eh>
<= span style=3D"color: hsl(120, 100%, 40%);">+

+char *
+strtok_r(char *s, const char *delim, char **last)
+{

+ char *spanp, *tok;
+ int c, sc;
+
+ {
+ return (NULL);
+ }
+
= +/*
+ * Skip (span) l= eading delimiters (s +=3D strspn(s, delim), sort of)=2E
+ */
+cont:
+ c =3D *s++;
+ for (spanp =3D (char *)delim; (sc =3D *spanp++) !=3D 0;)
+ {

+ if (c =3D=3D sc)
+ {
+ goto cont;
+ }
+ }
+ if (c =3D=3D= 0)
+ { /* no non-= delimiter characters */
+ *last =3D NULL;
+ return (NULL);
+ }
+ = tok =3D s - 1;
+

+ /*
+ * Scan token (scan for delimite= rs: s +=3D strcspn(s, delim), sort of)=2E
+ * Note that delim must have one NUL; we stop if = we see that, too=2E
+= */
+ for (;;)=
+ {
+ c =3D *s++;
+ spanp =3D (char *)delim;<= /span>
+ do+ {
+ if ((sc =3D *spanp++) =3D= =3D c)
+ {=
+ if = (c =3D=3D 0)
+ = {
+ = s =3D NULL;
= + else
+ {
+= s[-1] =3D '\0';
+ }
+ *last =3D s;
+ return (tok);
+ }
+ } while (sc !=3D 0);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+ /* NOTREACHED */
+}
+#endif
\ No newline at end of file
<= span>diff --git a/src/compat/compat=2Eh b/src/compat/compat=2Eh
<= span>index 6532b86=2E=2E9e6f95c 100644
--- a/src/compat/com= pat=2Eh
+++ b/src/compat/compat=2Eh
@@ -61,= 4 +61,9 @@

#endif

+#ifndef HAVE_STRTOK_R
+char *
+strtok_r(char *s, const char *delim= , char **last);

+#end= if
+
= #endif /* COMPAT_H */
diff --git a/src/openvpn/options_uti= l=2Ec b/src/openvpn/options_util=2Ec
index 47fe0bc=2E=2Ed72= ea25c 100644
--- a/src/openvpn/options_util=2Ec
<= span>+++ b/src/openvpn/options_util=2Ec
@@ -48,7 +48,8 @@
message =3D strstr(reason, "]") + 1;
/* null terminate the substring to only looks for flag= s between [ and ] */
*endofflags =3D '\x00'= ;;
- const char = *token =3D strtok(m, "[,");
+ char *lasts =3D NULL;
+ const char *token =3D strtok_r(m, "= ;[,", &lasts);
while (token)
{

if (!strncmp(token, "backo= ff ", strlen("backoff ")))
@@ -81,7 +82,7 @@=
{
msg(D_PUSH= _ERRORS, "WARNING: unknown AUTH_FAIL,TEMP flag: %s", token);
}
- token =3D strtok(NULL, "[,");
+ token =3D strtok_r(NULL, &= quot;[,", &lasts);
}
= }

diff --git a/src/openvpn/ssl_mbedtls= =2Ec b/src/openvpn/ssl_mbedtls=2Ec
index 8a0f7d2=2E=2E07caf= 08 100644
--- a/src/openvpn/ssl_mbedtls=2Ec
+++ b/src/openvpn/ssl_mbedtls=2Ec

@@ -318,9 +318,10 @@


/* Parse allowed ciphers, getting IDs *= /
int i =3D 0;
+ char *lasts =3D NULL;
tmp_ciphers_= orig =3D tmp_ciphers =3D string_alloc(ciphers, NULL);

- token =3D strtok(tmp_= ciphers, ":");
+ token =3D strtok_r(tmp_ciphers, ":", &lasts);=
while (token)
{
= ctx->allowed_ciphers[i] =3D mbedtls_ssl_get_ciphersuite_id(tls_transla= te_cipher_name(token));
@@ -328,7 +329,7 @@
{
i++;
}
- token =3D strtok= (NULL, ":");
- const char *token =3D strtok(tmp_c= iphers, ":");
+ char *lasts =3D NULL;
+ const char *token =3D strtok_r(tmp_ciphers, ":", &a= mp;lasts);
while (token)
{=
/*
@@ -174,7 +175,7 @@
= buf_puts(&new_list, ovpn_cipher_name);
= }
}
- token =3D strtok(NULL, ":");+ token =3D strtok_r(N= ULL, ":", &lasts);
}


@@ -207,15 +208,16 @@
{
char *tmp_ciphers =3D string_alloc(list, NULL);<= br> char *tmp_ciphers_orig =3D tmp_ciphers;
+ char *lasts =3D NULL;

- const char *tok= en =3D strtok(tmp_ciphers, ":");
+ const char *token =3D strtok_r(tmp_ciphers, &quo= t;:", &lasts);
while (token)
= {
if (0 =3D=3D strcmp(token, item)) {
break;
= }
- token = =3D strtok(NULL, ":");
+ token =3D strtok_r(NULL, ":", &lasts);
}
free(tmp_ciphers_orig);
diff --git a/src/openvpn/ssl_verify=2Ec b/src/ope= nvpn/ssl_verify=2Ec
index 9197adf=2E=2E162f68f 100644

--- a/src/openvpn/ssl_verify=2Ec
+++ b/src/openv= pn/ssl_verify=2Ec
@@ -868,7 +868,8 @@
= return false;
}

- const char *client_method =3D strt= ok(iv_sso, ",");
+ char *lasts =3D NULL;
+ const char *client_method =3D strtok_r(iv_sso, ",&quo= t;, &lasts);
bool supported =3D false;
<= span>
while (client_method)
@@ -878,7= +879,7 @@
supported =3D true;
break;
}
- client_method =3D strtok(NULL, ",&qu= ot;);
+ client= _method =3D strtok_r(NULL, ",", &lasts);
= }

gc_free(&gc);
diff --git a/tests/unit_tests/openvpn/Makefile=2Eam b/tests/unit_tests/ope= nvpn/Makefile=2Eam
index 1128eb4=2E=2Ed861ef9 100644=
--- a/tests/unit_tests/openvpn/Makefile=2Eam
+++ = b/tests/unit_tests/openvpn/Makefile=2Eam
@@ -107,6 +107,7 @= @
$(top_srcdir)/src/openvpn/base64=2Ec \
= $(top_srcdir)/src/openvpn/buffer=2Ec \
$(top_srcdir)/sr= c/compat/compat-strsep=2Ec \
+ $(top_srcdir)/src/compat/compat-strtok_r=2Ec \
= $(top_srcdir)/src/openvpn/crypto=2Ec \
$(top_srcdir)/src/= openvpn/cryptoapi=2Ec \
$(top_srcdir)/src/openvpn/crypto_= epoch=2Ec \
@@ -345,6 +346,7 @@
$(top_src= dir)/src/openvpn/platform=2Ec \
$(top_srcdir)/src/openvpn= /win32-util=2Ec \
$(top_srcdir)/src/compat/compat-strsep= =2Ec \
+ $(top_srcdir= )/src/compat/compat-strtok_r=2Ec \
$(top_srcdir)/src/open= vpn/ssl_util=2Ec

mbuf_testdriver_CFLAGS = =3D \

To view, visit change 1679=2E To= unsubscribe, or for help writing mail filters, visit settings=2E

Gerrit-MessageType: merged
Ge= rrit-Project: openvpn
Gerrit-Branch: ma= ster
Gerrit-Change-Id: I70560efd113308b= 7377424127eb2c1da4266371a
Gerrit-Change= -Number: 1679
Gerrit-PatchSet: 6
=
Gerrit-Owner: plaisthos <arne-openvpn@rfc2= 549=2Eorg>
Gerrit-Reviewer: flichten= held <frank@lichtenheld=2Ecom>
Ge= rrit-CC: openvpn-devel <openvpn-devel@lists=2Esourceforge=2Enet> --wppluVeuX6o=-- --===============1318835698950892666== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============1318835698950892666== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel --===============1318835698950892666==--