From: "plaisthos (Code Review)" Date: Mon, 25 Mar 2024 18:04:47 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: <89ee13542bd52b855d27cc5ed77c0aa023049d85-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="LLwum9NYQ7I="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Remove openvpn_snprintf and similar functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --LLwum9NYQ7I= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, ordex, plaisthos. Hello flichtenheld, ordex, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review+2 by ordex, Code-Review-1 by plaisthos The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: Remove openvpn_snprintf and similar functions ...................................................................... Remove openvpn_snprintf and similar functions Old Microsoft versions did strange behaviour but according to the newly added unit test and https://stackoverflow.com/questions/7706936/is-snprintf-always-null-termina= ting this is now standard conforming and we can use the normal snprintf method. Microsoft own documentation to swprintf also says you nowadays need to define _CRT_NON_CONFORMING_SWPRINTFS to get to non-standard behaviour. Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac Signed-off-by: Arne Schwabe --- M src/openvpn/buffer.c M src/openvpn/buffer.h M src/openvpn/crypto.c M src/openvpn/crypto_mbedtls.c M src/openvpn/dns.c M src/openvpn/env_set.c M src/openvpn/error.c M src/openvpn/init.c M src/openvpn/manage.c M src/openvpn/options.c M src/openvpn/pkcs11.c M src/openvpn/platform.c M src/openvpn/plugin.c M src/openvpn/pool.c M src/openvpn/proxy.c M src/openvpn/ps.c M src/openvpn/route.c M src/openvpn/run_command.h M src/openvpn/socket.c M src/openvpn/socks.c M src/openvpn/ssl_mbedtls.c M src/openvpn/ssl_ncp.c M src/openvpn/ssl_openssl.c M src/openvpn/ssl_verify.c M src/openvpn/ssl_verify_mbedtls.c M src/openvpn/ssl_verify_openssl.c M src/openvpn/tls_crypt.c M src/openvpn/tun.c M src/openvpn/win32.c M src/openvpn/win32.h M src/openvpn/xkey_helper.c M src/openvpnserv/common.c M src/openvpnserv/interactive.c M src/openvpnserv/service.h M src/openvpnserv/validate.c M tests/unit_tests/openvpn/test_buffer.c M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_pkcs11.c 38 files changed, 288 insertions(+), 333 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/547/2 diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 66fd63f..3a8069c 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -279,32 +279,6 @@ return ret; } - -/* - * This is necessary due to certain buggy implementations of snprintf, - * that don't guarantee null termination for size > 0. - * - * Return false on overflow. - * - * This functionality is duplicated in src/openvpnserv/common.c - * Any modifications here should be done to the other place as well. - */ - -bool -openvpn_snprintf(char *str, size_t size, const char *format, ...) -{ - va_list arglist; - int len =3D -1; - if (size > 0) - { - va_start(arglist, format); - len =3D vsnprintf(str, size, format, arglist); - va_end(arglist); - str[size - 1] =3D 0; - } - return (len >=3D 0 && len < size); -} - /* * write a string to the end of a buffer that was * truncated by buf_printf diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 7c2f75a..27c3199 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -448,19 +448,6 @@ */ bool buf_puts(struct buffer *buf, const char *str); -/* - * Like snprintf but guarantees null termination for size > 0 - */ -bool openvpn_snprintf(char *str, size_t size, const char *format, ...) -#ifdef __GNUC__ -#if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 3, 4))) -#else -__attribute__ ((format(__printf__, 3, 4))) -#endif -#endif -; - /* * remove/add trailing characters diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 5d05cc4..207f145 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -874,11 +874,11 @@ key_direction_state_init(&kds, key_direction); - openvpn_snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name); + snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name); init_key_ctx(&ctx->encrypt, &key2->keys[kds.out_key], kt, OPENVPN_OP_ENCRYPT, log_prefix); - openvpn_snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name); + snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name); init_key_ctx(&ctx->decrypt, &key2->keys[kds.in_key], kt, OPENVPN_OP_DECRYPT, log_prefix); diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 1a39752..c806719 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -128,7 +128,7 @@ { char prefix[256]; - if (!openvpn_snprintf(prefix, sizeof(prefix), "%s:%d", func, line)) + if (!snprintf(prefix, sizeof(prefix), "%s:%d", func, line)) { return mbed_log_err(flags, errval, func); } @@ -239,11 +239,11 @@ char header[1000+1] =3D { 0 }; char footer[1000+1] =3D { 0 }; =20 - if (!openvpn_snprintf(header, sizeof(header), "-----BEGIN %s-----\n", = name)) + if (!snprintf(header, sizeof(header), "-----BEGIN %s-----\n", name)) { return false; } - if (!openvpn_snprintf(footer, sizeof(footer), "-----END %s-----\n", na= me)) + if (!snprintf(footer, sizeof(footer), "-----END %s-----\n", name)) { return false; } @@ -278,11 +278,11 @@ char header[1000+1] =3D { 0 }; char footer[1000+1] =3D { 0 }; - if (!openvpn_snprintf(header, sizeof(header), "-----BEGIN %s-----", na= me)) + if (!snprintf(header, sizeof(header), "-----BEGIN %s-----", name)) { return false; } - if (!openvpn_snprintf(footer, sizeof(footer), "-----END %s-----", name= )) + if (!snprintf(footer, sizeof(footer), "-----END %s-----", name)) { return false; } diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 7de3991..0539ca5 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -349,11 +349,11 @@ if (j < 0) { - name_ok =3D openvpn_snprintf(name, sizeof(name), format, i); + name_ok =3D snprintf(name, sizeof(name), format, i); } else { - name_ok =3D openvpn_snprintf(name, sizeof(name), format, i, j); + name_ok =3D snprintf(name, sizeof(name), format, i, j); } if (!name_ok) diff --git a/src/openvpn/env_set.c b/src/openvpn/env_set.c index b13d01e..81ab59e 100644 --- a/src/openvpn/env_set.c +++ b/src/openvpn/env_set.c @@ -259,7 +259,7 @@ setenv_counter(struct env_set *es, const char *name, counter_type value) { char buf[64]; - openvpn_snprintf(buf, sizeof(buf), counter_format, value); + snprintf(buf, sizeof(buf), counter_format, value); setenv_str(es, name, buf); } @@ -267,7 +267,7 @@ setenv_int(struct env_set *es, const char *name, int value) { char buf[64]; - openvpn_snprintf(buf, sizeof(buf), "%d", value); + snprintf(buf, sizeof(buf), "%d", value); setenv_str(es, name, buf); } @@ -275,7 +275,7 @@ setenv_long_long(struct env_set *es, const char *name, long long value) { char buf[64]; - openvpn_snprintf(buf, sizeof(buf), "%" PRIi64, (int64_t)value); + snprintf(buf, sizeof(buf), "%" PRIi64, (int64_t)value); setenv_str(es, name, buf); } @@ -310,7 +310,7 @@ strcpy(tmpname, name); while (NULL !=3D env_set_get(es, tmpname) && counter < 1000) { - ASSERT(openvpn_snprintf(tmpname, tmpname_len, "%s_%u", name, count= er)); + ASSERT(snprintf(tmpname, tmpname_len, "%s_%u", name, counter)); counter++; } if (counter < 1000) diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 245a2d5..ec65d5e 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -274,14 +274,14 @@ if ((flags & M_ERRNO) && e) { - openvpn_snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)", - m1, openvpn_strerror(e, crt_error, &gc), e); + snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)", + m1, openvpn_strerror(e, crt_error, &gc), e); SWAP; } if (flags & M_OPTERR) { - openvpn_snprintf(m2, ERR_BUF_SIZE, "Options error: %s", m1); + snprintf(m2, ERR_BUF_SIZE, "Options error: %s", m1); SWAP; } @@ -321,10 +321,10 @@ const struct virtual_output *vo =3D msg_get_virtual_output(); if (vo) { - openvpn_snprintf(m2, ERR_BUF_SIZE, "%s%s%s", - prefix, - prefix_sep, - m1); + snprintf(m2, ERR_BUF_SIZE, "%s%s%s", + prefix, + prefix_sep, + m1); virtual_output_print(vo, flags, m2); } } diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f2ce926..bce2e09 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -359,7 +359,7 @@ char *out =3D malloc(len); check_malloc_return(out); - openvpn_snprintf(out, len, "%s,%s,%s,%s", ce->remote, ce->remote_p= ort, proto, status); + snprintf(out, len, "%s,%s,%s,%s", ce->remote, ce->remote_port, pro= to, status); *remote =3D out; } else diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 43c5507..89591ea 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -515,8 +515,8 @@ char out[32]; /* do in a roundabout way to work around possible mingw or mingw-glibc= bug */ - openvpn_snprintf(in, sizeof(in), counter_format, man->persist.bytes_in= + dco_read_bytes); - openvpn_snprintf(out, sizeof(out), counter_format, man->persist.bytes_= out + dco_write_bytes); + snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + dco_r= ead_bytes); + snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + dc= o_write_bytes); msg(M_CLIENT, ">BYTECOUNT:%s,%s", in, out); } @@ -528,8 +528,8 @@ char in[32]; char out[32]; /* do in a roundabout way to work around possible mingw or mingw-glibc= bug */ - openvpn_snprintf(in, sizeof(in), counter_format, *bytes_in_total); - openvpn_snprintf(out, sizeof(out), counter_format, *bytes_out_total); + snprintf(in, sizeof(in), counter_format, *bytes_in_total); + snprintf(out, sizeof(out), counter_format, *bytes_out_total); msg(M_CLIENT, ">BYTECOUNT_CLI:%lu,%s,%s", mdac->cid, in, out); mdac->bytecount_last_update =3D now; } diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 768332d..a9a44ba 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1427,7 +1427,7 @@ for (int i =3D 1; i <=3D opt_max; ++i) { char name[32]; - openvpn_snprintf(name, sizeof(name), "foreign_option_%d", i); + snprintf(name, sizeof(name), "foreign_option_%d", i); const char *env_str =3D env_set_get(es, name); const char *value =3D strchr(env_str, '=3D') + 1; @@ -1482,7 +1482,7 @@ while (o->foreign_option_index < opt_max) { char name[32]; - openvpn_snprintf(name, sizeof(name), "foreign_option_%d", opt_max-= -); + snprintf(name, sizeof(name), "foreign_option_%d", opt_max--); setenv_del(es, name); } } @@ -5671,8 +5671,8 @@ #ifndef ENABLE_SMALL { char script_name[100]; - openvpn_snprintf(script_name, sizeof(script_name), - "--%s script", type); + snprintf(script_name, sizeof(script_name), + "--%s script", type); if (check_cmd_access(*script, script_name, (in_chroot ? options->c= hroot_dir : NULL))) { diff --git a/src/openvpn/pkcs11.c b/src/openvpn/pkcs11.c index 35a02c2..418f6bb 100644 --- a/src/openvpn/pkcs11.c +++ b/src/openvpn/pkcs11.c @@ -201,7 +201,7 @@ CLEAR(token_resp); token_resp.defined =3D false; token_resp.nocache =3D true; - openvpn_snprintf( + snprintf( token_resp.username, sizeof(token_resp.username), "Please insert %s token", @@ -245,7 +245,7 @@ ASSERT(token!=3DNULL); - openvpn_snprintf(prompt, sizeof(prompt), "%s token", token->label); + snprintf(prompt, sizeof(prompt), "%s token", token->label); token_pass.defined =3D false; token_pass.nocache =3D true; @@ -719,7 +719,7 @@ id_resp.defined =3D false; id_resp.nocache =3D true; - openvpn_snprintf( + snprintf( id_resp.username, sizeof(id_resp.username), "Please specify PKCS#11 id to use" diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c index 9853dac..3d9d59e 100644 --- a/src/openvpn/platform.c +++ b/src/openvpn/platform.c @@ -564,9 +564,9 @@ { ++attempts; - if (!openvpn_snprintf(fname, sizeof(fname), fname_fmt, max_prefix_= len, - prefix, (unsigned long) get_random(), - (unsigned long) get_random())) + if (!snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len, + prefix, (unsigned long) get_random(), + (unsigned long) get_random())) { msg(M_WARN, "ERROR: temporary filename too long"); return NULL; diff --git a/src/openvpn/plugin.c b/src/openvpn/plugin.c index 2ad459c..944ce94 100644 --- a/src/openvpn/plugin.c +++ b/src/openvpn/plugin.c @@ -260,7 +260,7 @@ { char full[PATH_MAX]; - openvpn_snprintf(full, sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so= _pathname); + snprintf(full, sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so_pathnam= e); p->handle =3D dlopen(full, RTLD_NOW); } else @@ -409,7 +409,7 @@ gc_init(&gc); msg_fmt =3D gc_malloc(ERR_BUF_SIZE, false, &gc); - openvpn_snprintf(msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, for= mat); + snprintf(msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, format); x_msg_va(msg_flags, msg_fmt, arglist); gc_free(&gc); diff --git a/src/openvpn/pool.c b/src/openvpn/pool.c index f706c1a..e3c3708 100644 --- a/src/openvpn/pool.c +++ b/src/openvpn/pool.c @@ -766,7 +766,7 @@ ifconfig_pool_handle h; in_addr_t local, remote; char buf[256]; - openvpn_snprintf(buf, sizeof(buf), "common-name-%d", i); + snprintf(buf, sizeof(buf), "common-name-%d", i); #ifdef DUP_CN cn =3D NULL; #else diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 5c1cdcb..ba3d87c 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -582,9 +582,9 @@ { if (p->options.custom_headers[i].content) { - openvpn_snprintf(buf, sizeof(buf), "%s: %s", - p->options.custom_headers[i].name, - p->options.custom_headers[i].content); + snprintf(buf, sizeof(buf), "%s: %s", + p->options.custom_headers[i].name, + p->options.custom_headers[i].content); if (!strcasecmp(p->options.custom_headers[i].name, "Host")) { host_header_sent =3D true; @@ -592,8 +592,8 @@ } else { - openvpn_snprintf(buf, sizeof(buf), "%s", - p->options.custom_headers[i].name); + snprintf(buf, sizeof(buf), "%s", + p->options.custom_headers[i].name); if (!strncasecmp(p->options.custom_headers[i].name, "Host:", 5= )) { host_header_sent =3D true; @@ -609,7 +609,7 @@ if (!host_header_sent) { - openvpn_snprintf(buf, sizeof(buf), "Host: %s", host); + snprintf(buf, sizeof(buf), "Host: %s", host); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) { @@ -620,8 +620,8 @@ /* send User-Agent string if provided */ if (p->options.user_agent) { - openvpn_snprintf(buf, sizeof(buf), "User-Agent: %s", - p->options.user_agent); + snprintf(buf, sizeof(buf), "User-Agent: %s", + p->options.user_agent); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) { @@ -667,10 +667,10 @@ else { /* format HTTP CONNECT message */ - openvpn_snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", - host, - port, - p->options.http_version); + snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", + host, + port, + p->options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -692,8 +692,8 @@ break; case HTTP_AUTH_BASIC: - openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: B= asic %s", - username_password_as_base64(p, &gc)); + snprintf(buf, sizeof(buf), "Proxy-Authorization: Basic %s", + username_password_as_base64(p, &gc)); msg(D_PROXY, "Attempting Basic Proxy-Authorization"); dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) @@ -705,14 +705,14 @@ #if NTLM case HTTP_AUTH_NTLM2: /* keep-alive connection */ - openvpn_snprintf(buf, sizeof(buf), "Proxy-Connection: Keep= -Alive"); + snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive"); if (!send_line_crlf(sd, buf)) { goto error; } - openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: N= TLM %s", - ntlm_phase_1(p, &gc)); + snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s", + ntlm_phase_1(p, &gc)); msg(D_PROXY, "Attempting NTLM Proxy-Authorization phase 1"= ); dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) @@ -773,7 +773,7 @@ char get[80]; CLEAR(buf2); - openvpn_snprintf(get, sizeof(get), "%%*s NTLM %%%zus", siz= eof(buf2) - 1); + snprintf(get, sizeof(get), "%%*s NTLM %%%zus", sizeof(buf2= ) - 1); nparms =3D sscanf(buf, get, buf2); /* check for "Proxy-Authenticate: NTLM TlRM..." */ @@ -795,10 +795,10 @@ /* now send the phase 3 reply */ /* format HTTP CONNECT message */ - openvpn_snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", - host, - port, - p->options.http_version); + snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", + host, + port, + p->options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -809,7 +809,7 @@ } /* keep-alive connection */ - openvpn_snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Ali= ve"); + snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive"); if (!send_line_crlf(sd, buf)) { goto error; @@ -829,7 +829,7 @@ msg(D_PROXY, "NTLM Proxy-Authorization phase 3 failed:= received corrupted data from proxy server"); goto error; } - openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: N= TLM %s", np3); + snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",= np3); } msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -899,15 +899,15 @@ /* build the digest response */ - openvpn_snprintf(uri, sizeof(uri), "%s:%s", - host, - port); + snprintf(uri, sizeof(uri), "%s:%s", + host, + port); if (opaque) { const int len =3D strlen(opaque)+16; opaque_kv =3D gc_malloc(len, false, &gc); - openvpn_snprintf(opaque_kv, len, ", opaque=3D\"%s\"", = opaque); + snprintf(opaque_kv, len, ", opaque=3D\"%s\"", opaque); } DigestCalcHA1(algor, @@ -928,10 +928,10 @@ response); /* format HTTP CONNECT message */ - openvpn_snprintf(buf, sizeof(buf), "%s %s HTTP/%s", - http_method, - uri, - p->options.http_version); + snprintf(buf, sizeof(buf), "%s %s HTTP/%s", + http_method, + uri, + p->options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -948,21 +948,22 @@ } /* send digest response */ - int sret =3D openvpn_snprintf(buf, sizeof(buf), "Proxy-Aut= horization: Digest username=3D\"%s\", realm=3D\"%s\", nonce=3D\"%s\", uri= =3D\"%s\", qop=3D%s, nc=3D%s, cnonce=3D\"%s\", response=3D\"%s\"%s", - username, - realm, - nonce, - uri, - qop, - nonce_count, - cnonce, - response, - opaque_kv - ); + int sret =3D snprintf(buf, sizeof(buf), "Proxy-Authorizati= on: Digest username=3D\"%s\", realm=3D\"%s\", nonce=3D\"%s\", uri=3D\"%s\",= qop=3D%s, nc=3D%s, cnonce=3D\"%s\", response=3D\"%s\"%s", + username, + realm, + nonce, + uri, + qop, + nonce_count, + cnonce, + response, + opaque_kv + ); if (sret >=3D sizeof(buf)) { goto error; } + msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) { diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c index 7d9f9b5..4ca3a12 100644 --- a/src/openvpn/ps.c +++ b/src/openvpn/ps.c @@ -354,7 +354,7 @@ fnlen =3D strlen(journal_dir) + strlen(t) + 2; jfn =3D (char *) malloc(fnlen); check_malloc_return(jfn); - openvpn_snprintf(jfn, fnlen, "%s/%s", journal_dir, t); + snprintf(jfn, fnlen, "%s/%s", journal_dir, t); dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin %s -> %s",= jfn, f); fd =3D platform_open(jfn, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | = S_IWUSR | S_IRGRP); if (fd !=3D -1) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 909d6d2..68bbcfd 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1621,11 +1621,11 @@ if (rgi) { - openvpn_snprintf(out, sizeof(out), "%s %s %s dev %s", network, net= mask, gateway, rgi->iface); + snprintf(out, sizeof(out), "%s %s %s dev %s", network, netmask, ga= teway, rgi->iface); } else { - openvpn_snprintf(out, sizeof(out), "%s %s %s", network, netmask, g= ateway); + snprintf(out, sizeof(out), "%s %s %s", network, netmask, gateway); } bool ret =3D management_android_control(management, "ROUTE", out); status =3D ret ? RTA_SUCCESS : RTA_ERROR; @@ -2000,7 +2000,7 @@ #elif defined (TARGET_ANDROID) char out[64]; - openvpn_snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, d= evice); + snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device); status =3D management_android_control(management, "ROUTE6", out); diff --git a/src/openvpn/run_command.h b/src/openvpn/run_command.h index 52ab115..ccad307 100644 --- a/src/openvpn/run_command.h +++ b/src/openvpn/run_command.h @@ -66,8 +66,8 @@ { char msg[256]; - openvpn_snprintf(msg, sizeof(msg), - "WARNING: Failed running command (%s)", hook); + snprintf(msg, sizeof(msg), + "WARNING: Failed running command (%s)", hook); return openvpn_execve_check(a, es, flags | S_SCRIPT, msg); } diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index d2b82d5..24d1276 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -2983,11 +2983,11 @@ case AF_INET: if (flags & SA_IP_PORT) { - openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name= _prefix); + snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix); } else { - openvpn_snprintf(name_buf, sizeof(name_buf), "%s", name_pr= efix); + snprintf(name_buf, sizeof(name_buf), "%s", name_prefix); } inet_ntop(AF_INET, &addr->addr.in4.sin_addr, buf, sizeof(buf)); @@ -2995,7 +2995,7 @@ if ((flags & SA_IP_PORT) && addr->addr.in4.sin_port) { - openvpn_snprintf(name_buf, sizeof(name_buf), "%s_port", na= me_prefix); + snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefi= x); setenv_int(es, name_buf, ntohs(addr->addr.in4.sin_port)); } break; @@ -3006,19 +3006,19 @@ struct in_addr ia; memcpy(&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12], sizeof(ia.s_addr)); - openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name= _prefix); + snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix); inet_ntop(AF_INET, &ia, buf, sizeof(buf)); } else { - openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip6", nam= e_prefix); + snprintf(name_buf, sizeof(name_buf), "%s_ip6", name_prefix= ); inet_ntop(AF_INET6, &addr->addr.in6.sin6_addr, buf, sizeof= (buf)); } setenv_str(es, name_buf, buf); if ((flags & SA_IP_PORT) && addr->addr.in6.sin6_port) { - openvpn_snprintf(name_buf, sizeof(name_buf), "%s_port", na= me_prefix); + snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefi= x); setenv_int(es, name_buf, ntohs(addr->addr.in6.sin6_port)); } break; diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index b046910..8b8c01a 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -109,9 +109,10 @@ "Authentication not possible."); goto cleanup; } - int sret =3D openvpn_snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s", - (int) strlen(creds.username), creds.userna= me, - (int) strlen(creds.password), creds.passwo= rd); + + int sret =3D snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s", + (int) strlen(creds.username), creds.username, + (int) strlen(creds.password), creds.password); ASSERT(sret <=3D sizeof(to_send)); size =3D send(sd, to_send, strlen(to_send), MSG_NOSIGNAL); diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 0730d25..b0303b6 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -1531,16 +1531,16 @@ char s2[256]; s1[0] =3D s2[0] =3D 0; - openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s", - prefix, - mbedtls_ssl_get_version(ks_ssl->ctx), - mbedtls_ssl_get_ciphersuite(ks_ssl->ctx)); + snprintf(s1, sizeof(s1), "%s %s, cipher %s", + prefix, + mbedtls_ssl_get_version(ks_ssl->ctx), + mbedtls_ssl_get_ciphersuite(ks_ssl->ctx)); cert =3D mbedtls_ssl_get_peer_cert(ks_ssl->ctx); if (cert !=3D NULL) { - openvpn_snprintf(s2, sizeof(s2), ", %u bit key", - (unsigned int) mbedtls_pk_get_bitlen(&cert->pk)); + snprintf(s2, sizeof(s2), ", %u bit key", + (unsigned int) mbedtls_pk_get_bitlen(&cert->pk)); } msg(D_HANDSHAKE, "%s%s", s1, s2); diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 73ec9f5..968858e 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -198,8 +198,8 @@ size_t newlen =3D strlen(o->ncp_ciphers) + 1 + strlen(ciphername) + 1; char *ncp_ciphers =3D gc_malloc(newlen, false, &o->gc); - ASSERT(openvpn_snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers, - ciphername)); + ASSERT(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers, + ciphername)); o->ncp_ciphers =3D ncp_ciphers; } diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 6f29c3d..16a8c15 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1774,7 +1774,7 @@ if (!biofp) { char fn[256]; - openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggl= e); + snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle); biofp =3D fopen(fn, "w"); ASSERT(biofp); biofp_last_open =3D time(NULL); @@ -2116,8 +2116,8 @@ #endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } - openvpn_snprintf(buf, buflen, "%d bits %s%s", - EVP_PKEY_bits(pkey), type, curve); + snprintf(buf, buflen, "%d bits %s%s", + EVP_PKEY_bits(pkey), type, curve); } /** @@ -2137,12 +2137,12 @@ int signature_nid =3D X509_get_signature_nid(cert); if (signature_nid !=3D 0) { - openvpn_snprintf(sig, sizeof(sig), ", signature: %s", - OBJ_nid2sn(signature_nid)); + snprintf(sig, sizeof(sig), ", signature: %s", + OBJ_nid2sn(signature_nid)); } - openvpn_snprintf(buf, buflen, ", peer certificate: %s%s", - pkeybuf, sig); + snprintf(buf, buflen, ", peer certificate: %s%s", + pkeybuf, sig); EVP_PKEY_free(pkey); } @@ -2160,8 +2160,8 @@ char pkeybuf[128] =3D { 0 }; print_pkey_details(pkey, pkeybuf, sizeof(pkeybuf)); - openvpn_snprintf(buf, buflen, ", peer temporary key: %s", - pkeybuf); + snprintf(buf, buflen, ", peer temporary key: %s", + pkeybuf); EVP_PKEY_free(pkey); } @@ -2237,8 +2237,8 @@ return; } - openvpn_snprintf(buf, buflen, ", peer signing digest/type: %s %s", - peer_sig, peer_sig_type); + snprintf(buf, buflen, ", peer signing digest/type: %s %s", + peer_sig, peer_sig_type); } @@ -2261,11 +2261,11 @@ s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D 0; ciph =3D SSL_get_current_cipher(ks_ssl->ssl); - openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", - prefix, - SSL_get_version(ks_ssl->ssl), - SSL_CIPHER_get_version(ciph), - SSL_CIPHER_get_name(ciph)); + snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", + prefix, + SSL_get_version(ks_ssl->ssl), + SSL_CIPHER_get_version(ciph), + SSL_CIPHER_get_name(ciph)); X509 *cert =3D SSL_get_peer_certificate(ks_ssl->ssl); if (cert) diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index c7d7799..ec7ff23 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -421,12 +421,12 @@ } /* export subject name string as environmental variable */ - openvpn_snprintf(envname, sizeof(envname), "tls_id_%d", cert_depth); + snprintf(envname, sizeof(envname), "tls_id_%d", cert_depth); setenv_str(es, envname, subject); #if 0 /* export common name string as environmental variable */ - openvpn_snprintf(envname, sizeof(envname), "tls_common_name_%d", cert_= depth); + snprintf(envname, sizeof(envname), "tls_common_name_%d", cert_depth); setenv_str(es, envname, common_name); #endif @@ -435,24 +435,24 @@ struct buffer sha1 =3D x509_get_sha1_fingerprint(peer_cert, &gc); struct buffer sha256 =3D x509_get_sha256_fingerprint(peer_cert, &g= c); - openvpn_snprintf(envname, sizeof(envname), "tls_digest_%d", cert_d= epth); + snprintf(envname, sizeof(envname), "tls_digest_%d", cert_depth); setenv_str(es, envname, format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &gc)= ); - openvpn_snprintf(envname, sizeof(envname), "tls_digest_sha256_%d", - cert_depth); + snprintf(envname, sizeof(envname), "tls_digest_sha256_%d", + cert_depth); setenv_str(es, envname, format_hex_ex(BPTR(&sha256), BLEN(&sha256), 0, 1, ":", = &gc)); } =20 /* export serial number as environmental variable */ serial =3D backend_x509_get_serial(peer_cert, &gc); - openvpn_snprintf(envname, sizeof(envname), "tls_serial_%d", cert_depth= ); + snprintf(envname, sizeof(envname), "tls_serial_%d", cert_depth); setenv_str(es, envname, serial); /* export serial number in hex as environmental variable */ serial =3D backend_x509_get_serial_hex(peer_cert, &gc); - openvpn_snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert_d= epth); + snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert_depth); setenv_str(es, envname, serial); gc_free(&gc); @@ -569,7 +569,7 @@ goto cleanup; } - if (!openvpn_snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATO= R, serial)) + if (!snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR, seria= l)) { msg(D_HANDSHAKE, "VERIFY CRL: filename overflow"); goto cleanup; @@ -938,9 +938,9 @@ if (!check_auth_pending_method(multi->peer_info, pending_metho= d)) { char buf[128]; - openvpn_snprintf(buf, sizeof(buf), - "Authentication failed, required pending = auth " - "method '%s' not supported", pending_meth= od); + snprintf(buf, sizeof(buf), + "Authentication failed, required pending auth " + "method '%s' not supported", pending_method); auth_set_client_reason(multi, buf); msg(M_INFO, "Client does not supported auth pending method= " "'%s'", pending_method); diff --git a/src/openvpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbed= tls.c index a801cd3..ca14ceb 100644 --- a/src/openvpn/ssl_verify_mbedtls.c +++ b/src/openvpn/ssl_verify_mbedtls.c @@ -86,8 +86,8 @@ char *serial =3D backend_x509_get_serial(cert, &gc); ret =3D mbedtls_x509_crt_verify_info(errstr, sizeof(errstr)-1, "",= *flags); - if (ret <=3D 0 && !openvpn_snprintf(errstr, sizeof(errstr), - "Could not retrieve error string= , flags=3D%" PRIx32, *flags)) + if (ret <=3D 0 && !snprintf(errstr, sizeof(errstr), + "Could not retrieve error string, flags= =3D%" PRIx32, *flags)) { errstr[0] =3D '\0'; } @@ -307,7 +307,7 @@ name_expand_size =3D 64 + strlen(name); name_expand =3D (char *) malloc(name_expand_size); check_malloc_return(name_expand); - openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, n= ame); + snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name); setenv_str(es, name_expand, value); free(name_expand); } @@ -431,13 +431,13 @@ if (0 =3D=3D mbedtls_oid_get_attr_short_name(&name->oid, &shortnam= e) ) { - openvpn_snprintf(name_expand, sizeof(name_expand), "X509_%d_%s= ", - cert_depth, shortname); + snprintf(name_expand, sizeof(name_expand), "X509_%d_%s", + cert_depth, shortname); } else { - openvpn_snprintf(name_expand, sizeof(name_expand), "X509_%d_\?= \?", - cert_depth); + snprintf(name_expand, sizeof(name_expand), "X509_%d_\?\?", + cert_depth); } for (i =3D 0; i < name->val.len; i++) diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_open= ssl.c index ec3a7cf..7d41d4a 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -279,7 +279,7 @@ gc_free(&gc); return FAILURE; } - openvpn_snprintf(common_name, cn_len, "0x%s", serial); + snprintf(common_name, cn_len, "0x%s", serial); gc_free(&gc); } else @@ -454,7 +454,7 @@ name_expand_size =3D 64 + strlen(name); name_expand =3D (char *) malloc(name_expand_size); check_malloc_return(name_expand); - openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, n= ame); + snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name); setenv_str(es, name_expand, value); free(name_expand); } @@ -597,8 +597,8 @@ name_expand_size =3D 64 + strlen(objbuf); name_expand =3D (char *) malloc(name_expand_size); check_malloc_return(name_expand); - openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", cert= _depth, - objbuf); + snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth, + objbuf); string_mod(name_expand, CC_PRINT, CC_CRLF, '_'); string_mod((char *)buf, CC_PRINT, CC_CRLF, '_'); setenv_str_incr(es, name_expand, (char *)buf); diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index 6ef1c7d..90fe6e9 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -574,8 +574,8 @@ } char metadata_type_str[4] =3D { 0 }; /* Max value: 255 */ - openvpn_snprintf(metadata_type_str, sizeof(metadata_type_str), - "%i", (uint8_t) metadata_type); + snprintf(metadata_type_str, sizeof(metadata_type_str), + "%i", (uint8_t) metadata_type); struct env_set *es =3D env_set_create(NULL); setenv_str(es, "script_type", "tls-crypt-v2-verify"); setenv_str(es, "metadata_type", metadata_type_str); diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index f550e9c..d01515d 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1114,8 +1114,8 @@ #elif defined(TARGET_ANDROID) char out6[64]; - openvpn_snprintf(out6, sizeof(out6), "%s/%d %d", - ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); + snprintf(out6, sizeof(out6), "%s/%d %d", + ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); management_android_control(management, "IFCONFIG6", out6); #elif defined(TARGET_SOLARIS) argv_printf(&argv, "%s %s inet6 unplumb", IFCONFIG_PATH, ifname); @@ -1362,8 +1362,8 @@ top =3D "undef"; } - openvpn_snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, - ifconfig_remote_netmask, tun_mtu, top); + snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, + ifconfig_remote_netmask, tun_mtu, top); management_android_control(management, "IFCONFIG", out); #elif defined(TARGET_SOLARIS) @@ -1912,7 +1912,7 @@ */ if (dev_node) { - openvpn_snprintf(tunname, sizeof(tunname), "%s", dev_node); + snprintf(tunname, sizeof(tunname), "%s", dev_node); } else { @@ -1926,10 +1926,10 @@ { for (int i =3D 0; i < 256; ++i) { - openvpn_snprintf(tunname, sizeof(tunname), - "/dev/%s%d", dev, i); - openvpn_snprintf(dynamic_name, sizeof(dynamic_name), - "%s%d", dev, i); + snprintf(tunname, sizeof(tunname), + "/dev/%s%d", dev, i); + snprintf(dynamic_name, sizeof(dynamic_name), + "%s%d", dev, i); if ((tt->fd =3D open(tunname, O_RDWR)) > 0) { dynamic_opened =3D true; @@ -1947,7 +1947,7 @@ */ else { - openvpn_snprintf(tunname, sizeof(tunname), "/dev/%s", dev); + snprintf(tunname, sizeof(tunname), "/dev/%s", dev); } } @@ -2002,8 +2002,8 @@ { for (int i =3D 0; i < 256; ++i) { - openvpn_snprintf(dynamic_name, sizeof(dynamic_name), - "%s%d", dev, i); + snprintf(dynamic_name, sizeof(dynamic_name), + "%s%d", dev, i); int ret =3D open_tun_dco(tt, ctx, dynamic_name); if (ret =3D=3D 0) { @@ -2519,7 +2519,7 @@ tt->actual_name =3D (char *) malloc(32); check_malloc_return(tt->actual_name); - openvpn_snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa); + snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa); if (tt->type =3D=3D DEV_TYPE_TAP) { @@ -3509,7 +3509,7 @@ int i; for (i =3D 0; i<99; i++) { - openvpn_snprintf(tunname, sizeof(tunname), "/dev/tap%d", i); + snprintf(tunname, sizeof(tunname), "/dev/tap%d", i); if (access( tunname, F_OK ) < 0 && errno =3D=3D ENOENT) { break; @@ -3520,7 +3520,7 @@ msg( M_FATAL, "cannot find unused tap device" ); } - openvpn_snprintf( dynamic_name, sizeof(dynamic_name), "tap%d", i ); + snprintf( dynamic_name, sizeof(dynamic_name), "tap%d", i ); dev =3D dynamic_name; } else /* name given, sanity chec= k */ @@ -3536,7 +3536,7 @@ msg( M_FATAL, "TAP device name must be '--dev tapNNNN'" ); } - openvpn_snprintf(tunname, sizeof(tunname), "/dev/%s", dev); + snprintf(tunname, sizeof(tunname), "/dev/%s", dev); } /* pre-existing device? @@ -3956,8 +3956,8 @@ ADAPTER_KEY); } - openvpn_snprintf(unit_string, sizeof(unit_string), "%s\\%s", - ADAPTER_KEY, enum_name); + snprintf(unit_string, sizeof(unit_string), "%s\\%s", + ADAPTER_KEY, enum_name); status =3D RegOpenKeyEx( HKEY_LOCAL_MACHINE, @@ -4098,9 +4098,9 @@ NETWORK_CONNECTIONS_KEY); } - openvpn_snprintf(connection_string, sizeof(connection_string), - "%s\\%s\\Connection", - NETWORK_CONNECTIONS_KEY, enum_name); + snprintf(connection_string, sizeof(connection_string), + "%s\\%s\\Connection", + NETWORK_CONNECTIONS_KEY, enum_name); status =3D RegOpenKeyEx( HKEY_LOCAL_MACHINE, @@ -4984,7 +4984,7 @@ DWORD index; ULONG aindex; wchar_t wbuf[256]; - openvpn_swprintf(wbuf, SIZE(wbuf), L"\\DEVICE\\TCPIP_%hs", guid); + swprintf(wbuf, SIZE(wbuf), L"\\DEVICE\\TCPIP_%hs", guid); if (GetAdapterIndex(wbuf, &aindex) !=3D NO_ERROR) { index =3D TUN_ADAPTER_INDEX_INVALID; @@ -5164,10 +5164,10 @@ } /* Open Windows TAP-Windows adapter */ - openvpn_snprintf(device_path, sizeof(device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, - TAP_WIN_SUFFIX); + snprintf(device_path, sizeof(device_path), "%s%s%s", + USERMODEDEVICEDIR, + device_guid, + TAP_WIN_SUFFIX); hand =3D CreateFile( device_path, @@ -5208,10 +5208,10 @@ } =20 /* Open Windows TAP-Windows adapter */ - openvpn_snprintf(device_path, sizeof(device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, - TAP_WIN_SUFFIX); + snprintf(device_path, sizeof(device_path), "%s%s%s", + USERMODEDEVICEDIR, + device_guid, + TAP_WIN_SUFFIX); hand =3D CreateFile( device_path, @@ -6607,10 +6607,10 @@ else { /* Open TAP-Windows */ - openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "= %s%s%s", - USERMODEDEVICEDIR, - device_guid, - TAP_WIN_SUFFIX); + snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s", + USERMODEDEVICEDIR, + device_guid, + TAP_WIN_SUFFIX); path =3D tuntap_device_path; } diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 27d82c5..98955ba 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -885,8 +885,8 @@ char force_path[256]; char *sysroot =3D get_win_sys_path(); - if (!openvpn_snprintf(force_path, sizeof(force_path), "PATH=3D%s\\Syst= em32;%s;%s\\System32\\Wbem", - sysroot, sysroot, sysroot)) + if (!snprintf(force_path, sizeof(force_path), "PATH=3D%s\\System32;%s;= %s\\System32\\Wbem", + sysroot, sysroot, sysroot)) { msg(M_WARN, "env_block: default path truncated to %s", force_path); } @@ -1483,26 +1483,11 @@ } bool -openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *con= st format, ...) -{ - va_list arglist; - int len =3D -1; - if (size > 0) - { - va_start(arglist, format); - len =3D vswprintf(str, size, format, arglist); - va_end(arglist); - str[size - 1] =3D L'\0'; - } - return (len >=3D 0 && len < size); -} - -bool get_openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size) { WCHAR reg_path[256]; HKEY hkey; - openvpn_swprintf(reg_path, _countof(reg_path), L"SOFTWARE\\" PACKAGE_N= AME); + swprintf(reg_path, _countof(reg_path), L"SOFTWARE\\" PACKAGE_NAME); LONG status =3D RegOpenKeyExW(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_REA= D, &hkey); if (status !=3D ERROR_SUCCESS) @@ -1528,7 +1513,7 @@ /* if we cannot find installation path from the registry, * use Windows directory as a fallback */ - openvpn_swprintf(install_path, _countof(install_path), L"%ls", ssl= _fallback_dir); + swprintf(install_path, _countof(install_path), L"%ls", ssl_fallbac= k_dir); } if ((install_path[wcslen(install_path) - 1]) =3D=3D L'\\') @@ -1553,7 +1538,7 @@ if (size =3D=3D 0) { WCHAR val[MAX_PATH] =3D {0}; - openvpn_swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install= _path, ossl_env[i].value); + swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, o= ssl_env[i].value); _wputenv_s(ossl_env[i].name, val); } } diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 974fe02d..fd75992 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -319,14 +319,6 @@ int openvpn_execve(const struct argv *a, const struct env_set *es, const unsig= ned int flags); -/* - * openvpn_swprintf() is currently only used by Windows code paths - * and when enabled for all platforms it will currently break older - * OpenBSD versions lacking vswprintf(3) support in their libc. - */ -bool -openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *con= st format, ...); - /* Sleep that can be interrupted by signals and exit event */ void win32_sleep(const int n); diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.c index c803323..283c95d 100644 --- a/src/openvpn/xkey_helper.c +++ b/src/openvpn/xkey_helper.c @@ -205,7 +205,7 @@ } else { - openvpn_snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=3D%s= ", alg.mdname); + snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=3D%s", alg.m= dname); } } else if (!strcmp(alg.keytype, "ED448") || !strcmp(alg.keytype, "ED2551= 9")) @@ -229,8 +229,8 @@ /* For undigested message, add hashalg=3Ddigest parameter */ else { - openvpn_snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s", - "RSA_PKCS1_PADDING", alg.mdname); + snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s", + "RSA_PKCS1_PADDING", alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPA= DDING) @@ -240,8 +240,8 @@ } else if (!strcmp(alg.padmode, "pss") && (flags & MF_EXTERNAL_KEY_PSSPA= D)) { - openvpn_snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s,saltle= n=3D%s", - "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen); + snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s,saltlen=3D%s", + "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen); } else { diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index bd0a484..96bf800 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -27,36 +27,6 @@ LPCTSTR service_instance =3D TEXT(""); static wchar_t win_sys_path[MAX_PATH]; -/* - * These are necessary due to certain buggy implementations of (v)snprintf, - * that don't guarantee null termination for size > 0. - */ -BOOL -openvpn_vswprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist) -{ - int len =3D -1; - if (size > 0) - { - len =3D vswprintf_s(str, size, format, arglist); - str[size - 1] =3D 0; - } - return (len >=3D 0 && (size_t)len < size); -} - -BOOL -openvpn_swprintf(LPTSTR str, size_t size, LPCTSTR format, ...) -{ - va_list arglist; - BOOL res =3D FALSE; - if (size > 0) - { - va_start(arglist, format); - res =3D openvpn_vswprintf(str, size, format, arglist); - va_end(arglist); - } - return res; -} - static DWORD GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR def= ault_value) { @@ -66,7 +36,7 @@ if (status =3D=3D ERROR_FILE_NOT_FOUND && default_value) { size_t len =3D size/sizeof(data[0]); - if (openvpn_swprintf(data, len, default_value)) + if (swprintf(data, len, default_value)) { status =3D ERROR_SUCCESS; } @@ -93,7 +63,7 @@ TCHAR install_path[MAX_PATH]; TCHAR default_value[MAX_PATH]; - openvpn_swprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKA= GE_NAME "%ls"), service_instance); + swprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKAGE_NAME = "%ls"), service_instance); LONG status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_READ= , &key); if (status !=3D ERROR_SUCCESS) @@ -110,15 +80,15 @@ goto out; } - openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\bi= n\\openvpn.exe"), - install_path); + swprintf(default_value, _countof(default_value), TEXT("%ls\\bin\\openv= pn.exe"), + install_path); error =3D GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->e= xe_path), default_value); if (error !=3D ERROR_SUCCESS) { goto out; } - openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\co= nfig"), install_path); + swprintf(default_value, _countof(default_value), TEXT("%ls\\config"), = install_path); error =3D GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(= s->config_dir), default_value); if (error !=3D ERROR_SUCCESS) @@ -133,7 +103,7 @@ goto out; } - openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\lo= g"), install_path); + swprintf(default_value, _countof(default_value), TEXT("%ls\\log"), ins= tall_path); error =3D GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log= _dir), default_value); if (error !=3D ERROR_SUCCESS) { @@ -229,7 +199,7 @@ else { tmp[wcslen(tmp) - 2] =3D TEXT('\0'); /* remove CR/LF characters */ - openvpn_swprintf(buf, _countof(buf), TEXT("%ls (0x%x)"), tmp, erro= r); + swprintf(buf, _countof(buf), TEXT("%ls (0x%x)"), tmp, error); } if (tmp) @@ -259,12 +229,12 @@ hEventSource =3D RegisterEventSource(NULL, APPNAME); if (hEventSource !=3D NULL) { - openvpn_swprintf(msg[0], _countof(msg[0]), - TEXT("%ls%ls%ls: %ls"), APPNAME, service_instance, - (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT= (""), err_msg); + swprintf(msg[0], _countof(msg[0]), + TEXT("%ls%ls%ls: %ls"), APPNAME, service_instance, + (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), er= r_msg); va_start(arglist, format); - openvpn_vswprintf(msg[1], _countof(msg[1]), format, arglist); + vswprintf(msg[1], _countof(msg[1]), format, arglist); va_end(arglist); const TCHAR *mesg[] =3D { msg[0], msg[1] }; diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index d32223c..ee56989 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -311,7 +311,7 @@ * Same format as error messages (3 line string) with error =3D 0 in * 0x%08x format, PID on line 2 and a description "Process ID" on line= 3 */ - openvpn_swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, m= sg); + swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, msg); WritePipeAsync(pipe, buf, (DWORD)(wcslen(buf) * 2), count, events); } @@ -385,9 +385,9 @@ if (!argv) { - openvpn_swprintf(errmsg, capacity, - L"Cannot validate options: CommandLineToArgvW fai= led with error =3D 0x%08x", - GetLastError()); + swprintf(errmsg, capacity, + L"Cannot validate options: CommandLineToArgvW failed with= error =3D 0x%08x", + GetLastError()); goto out; } @@ -407,8 +407,8 @@ if (!CheckOption(workdir, 2, argv_tmp, &settings)) { - openvpn_swprintf(errmsg, capacity, msg1, argv[0], workdir, - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg1, argv[0], workdir, + settings.ovpn_admin_group); } goto out; } @@ -424,13 +424,13 @@ { if (wcscmp(L"--config", argv[i]) =3D=3D 0 && argc-i > 1) { - openvpn_swprintf(errmsg, capacity, msg1, argv[i+1], workdi= r, - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg1, argv[i+1], workdir, + settings.ovpn_admin_group); } else { - openvpn_swprintf(errmsg, capacity, msg2, argv[i], - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg2, argv[i], + settings.ovpn_admin_group); } goto out; } @@ -985,7 +985,7 @@ HANDLE wait_handles[2] =3D {rdns_semaphore, exit_event}; - openvpn_swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path(), L"i= pconfig.exe"); + swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path(), L"ipconfig.= exe"); if (WaitForMultipleObjects(2, wait_handles, FALSE, timeout) =3D=3D WAI= T_OBJECT_0) { @@ -1064,7 +1064,7 @@ } /* Path of netsh */ - openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"netsh.exe"); + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"ne= tsh.exe"); /* cmd template: * netsh interface $proto $action dns $if_name $addr [validate=3Dno] @@ -1080,7 +1080,7 @@ goto out; } - openvpn_swprintf(cmdline, ncmdline, fmt, proto, action, if_name, addr); + swprintf(cmdline, ncmdline, fmt, proto, action, if_name, addr); if (IsWindows7OrGreater()) { @@ -1124,7 +1124,7 @@ } /* Path of netsh */ - openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"netsh.exe"); + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"ne= tsh.exe"); /* cmd template: * netsh interface ip $action wins $if_name $static $addr @@ -1141,7 +1141,7 @@ goto out; } - openvpn_swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static,= addr); + swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr); err =3D ExecCommand(argv0, cmdline, timeout); @@ -1167,7 +1167,7 @@ wchar_t *cmdline =3D NULL; int timeout =3D 10000; /* in msec */ - openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"wbem\\wmic.exe"); + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"wb= em\\wmic.exe"); const wchar_t *fmt; /* comma separated list must be enclosed in parenthesis */ @@ -1188,8 +1188,8 @@ return ERROR_OUTOFMEMORY; } - openvpn_swprintf(cmdline, ncmdline, fmt, if_index, action, - data ? data : L""); + swprintf(cmdline, ncmdline, fmt, if_index, action, + data ? data : L""); err =3D ExecCommand(argv0, cmdline, timeout); free(cmdline); @@ -1453,7 +1453,7 @@ wchar_t argv0[MAX_PATH]; /* Path of netsh */ - openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"netsh.exe"); + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"ne= tsh.exe"); /* cmd template: * netsh interface ipv4 set address name=3D$if_index source=3Ddhcp @@ -1471,7 +1471,7 @@ return err; } - openvpn_swprintf(cmdline, ncmdline, fmt, dhcp->iface.index); + swprintf(cmdline, ncmdline, fmt, dhcp->iface.index); err =3D ExecCommand(argv0, cmdline, timeout); @@ -1970,8 +1970,8 @@ goto out; } - openvpn_swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name), - TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service_%lu"), ser= vice_instance, GetCurrentThreadId()); + swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name), + TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service_%lu"), service_ins= tance, GetCurrentThreadId()); ovpn_pipe =3D CreateNamedPipe(ovpn_pipe_name, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_= INSTANCE | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE = | PIPE_WAIT, 1, 128, 128, 0, NULL); @@ -2003,8 +2003,8 @@ ReturnLastError(pipe, L"malloc"); goto out; } - openvpn_swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %"= PRIuPTR, - sud.options, svc_pipe); + swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %" PRIuPTR, + sud.options, svc_pipe); if (!CreateEnvironmentBlock(&user_env, imp_token, FALSE)) { @@ -2079,8 +2079,8 @@ else if (exit_code !=3D 0) { WCHAR buf[256]; - openvpn_swprintf(buf, _countof(buf), - L"OpenVPN exited with error: exit code =3D %lu", = exit_code); + swprintf(buf, _countof(buf), + L"OpenVPN exited with error: exit code =3D %lu", exit_cod= e); ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event); } Undo(&undo_lists); @@ -2174,7 +2174,7 @@ initialized =3D TRUE; } - openvpn_swprintf(pipe_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\" = PACKAGE "%ls\\service"), service_instance); + swprintf(pipe_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\" PACKAGE = "%ls\\service"), service_instance); pipe =3D CreateNamedPipe(pipe_name, flags, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIP= E_REJECT_REMOTE_CLIENTS, PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, NULL); diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h index 3acf08c..6d0827d 100644 --- a/src/openvpnserv/service.h +++ b/src/openvpnserv/service.h @@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list a= rglist); - -BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...); - -BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t= *const format, ...); - DWORD GetOpenvpnSettings(settings_t *s); BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *st= atus); diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index 5f7acd7..9563fa5 100644 --- a/src/openvpnserv/validate.c +++ b/src/openvpnserv/validate.c @@ -68,7 +68,7 @@ /* convert fname to full path */ if (PathIsRelativeW(fname) ) { - openvpn_swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname); + swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname); config_file =3D tmp; } else diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/open= vpn/test_buffer.c index 52ffb54..9a61f2f 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -354,6 +354,56 @@ assert_string_equal(buf, "There is a .'nice.' \"1234\" [.] year old .t= ree!"); } +static void +test_snprintf(void **state) +{ + /* we used to have a custom openvpn_snprintf function because some + * OS (the comment did not specify which) did not always put the + * null byte there. So we unit test this to be sure. + * + * This probably refers to the MSVC behaviour, see also + * https://stackoverflow.com/questions/7706936/is-snprintf-always-null= -terminating + */ + + /* Instead of trying to trick the compiler here, disable the warnings + * for this unit test. We know that are doing this that are truncated + * and we want to test that */ +#if defined(__GNUC__) +/* some clang version do not understand -Wformat-truncation, so ignore the + * warning to avoid warnings/errors (-Werror) about unknown pragma/option = */ +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation" +#endif + + char buf[10] =3D { 'a' }; + int ret =3D 0; + + ret =3D snprintf(buf, sizeof(buf), "0123456789abcde"); + assert_int_equal(ret, 15); + assert_int_equal(buf[9], '\0'); + + memset(buf, 'b', sizeof(buf)); + ret =3D snprintf(buf, sizeof(buf), "- %d - %d -", 77, 88); + assert_int_equal(ret, 11); + assert_int_equal(buf[9], '\0'); + + memset(buf, 'c', sizeof(buf)); + ret =3D snprintf(buf, sizeof(buf), "- %8.2f", 77.8899); + assert_int_equal(ret, 10); + assert_int_equal(buf[9], '\0'); + +#if defined(__GNUC__) +#if defined(__clang__) +#pragma GCC diagnostic pop +#endif +#pragma GCC diagnostic pop +#endif +} + int main(void) { @@ -387,6 +437,7 @@ cmocka_unit_test(test_buffer_free_gc_two), cmocka_unit_test(test_buffer_gc_realloc), cmocka_unit_test(test_character_class), + cmocka_unit_test(test_snprintf) }; return cmocka_run_group_tests_name("buffer", tests, NULL, NULL); diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tests/o= penvpn/test_cryptoapi.c index 87f6208..98102ef 100644 --- a/tests/unit_tests/openvpn/test_cryptoapi.c +++ b/tests/unit_tests/openvpn/test_cryptoapi.c @@ -271,7 +271,7 @@ for (struct test_cert *c =3D certs; c->cert; c++) { - openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s",= c->hash); + snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash= ); ctx =3D find_certificate_in_store(select_string, user_store); if (ctx) { @@ -304,7 +304,7 @@ for (struct test_cert *c =3D certs; c->cert; c++) { - openvpn_snprintf(select_string, sizeof(select_string), "SUBJ:%s", = c->cname); + snprintf(select_string, sizeof(select_string), "SUBJ:%s", c->cname= ); ctx =3D find_certificate_in_store(select_string, user_store); /* In this case we expect a successful return as there is at least= one valid * cert that matches the common name. But the returned cert may no= t exactly match @@ -337,7 +337,7 @@ for (struct test_cert *c =3D certs; c->cert; c++) { - openvpn_snprintf(select_string, sizeof(select_string), "ISSUER:%s"= , c->issuer); + snprintf(select_string, sizeof(select_string), "ISSUER:%s", c->iss= uer); ctx =3D find_certificate_in_store(select_string, user_store); /* In this case we expect a successful return as there is at least= one valid * cert that matches the issuer. But the returned cert may not exa= ctly match @@ -411,7 +411,7 @@ { continue; } - openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s",= c->hash); + snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash= ); if (Load_CryptoAPI_certificate(select_string, &x509, &privkey) != =3D 1) { fail_msg("Load_CryptoAPI_certificate failed: <%s>", c->friendl= y_name); @@ -446,7 +446,7 @@ SSL_CTX *ssl_ctx =3D SSL_CTX_new_ex(tls_libctx, NULL, SSLv23_clien= t_method()); assert_non_null(ssl_ctx); - openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s",= c->hash); + snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash= ); if (!SSL_CTX_use_CryptoAPI_certificate(ssl_ctx, select_string)) { fail_msg("SSL_CTX_use_CryptoAPI_certificate failed: <%s>", c->= friendly_name); diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_tests/open= vpn/test_pkcs11.c index a48e404..84ebb29 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -161,7 +161,7 @@ } else if (flags & GET_USER_PASS_PASSWORD_ONLY) { - openvpn_snprintf(up->password, sizeof(up->password), "%s", PIN); + snprintf(up->password, sizeof(up->password), "%s", PIN); } else { @@ -204,8 +204,8 @@ { fail_msg("make tmpfile using template <%s> failed (error =3D %d)",= softhsm2_conf_path, errno); } - openvpn_snprintf(config, sizeof(config), "directories.tokendir=3D%s/", - softhsm2_tokens_path); + snprintf(config, sizeof(config), "directories.tokendir=3D%s/", + softhsm2_tokens_path); assert_int_equal(write(fd, config, strlen(config)), strlen(config)); close(fd); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/547?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e12ac Gerrit-Change-Number: 547 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: ordex Gerrit-MessageType: newpatchset --LLwum9NYQ7I= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, ordex, plaisthos. <= /p>

plaisthos uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/547?usp=3Demail">View Chang= e

The following approvals got outdated and were removed: Code-Review+2 by ordex, Code-Review-1 by plaisthos

The change is no l= onger submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied = now.

Remove openvpn_snprintf and similar functions

Old Microsoft ver= sions did strange behaviour but according to the
newly added unit test a= nd
https://stackoverflow.com/questions/7706936/is-snprintf-always-null-t= erminating
this is now standard conforming and we can use the normal snp= rintf
method.

Microsoft own documentation to swprintf also says y= ou nowadays need to
define _CRT_NON_CONFORMING_SWPRINTFS to get to non-s= tandard behaviour.

Change-Id: I07096977e3b562bcb5d2c6f11673a4175b8e1= 2ac
Signed-off-by: Arne Schwabe <arne@...1227...>
---
M src/= openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto.c
M s= rc/openvpn/crypto_mbedtls.c
M src/openvpn/dns.c
M src/openvpn/env_set= .c
M src/openvpn/error.c
M src/openvpn/init.c
M src/openvpn/manage= .c
M src/openvpn/options.c
M src/openvpn/pkcs11.c
M src/openvpn/pl= atform.c
M src/openvpn/plugin.c
M src/openvpn/pool.c
M src/openvpn= /proxy.c
M src/openvpn/ps.c
M src/openvpn/route.c
M src/openvpn/ru= n_command.h
M src/openvpn/socket.c
M src/openvpn/socks.c
M src/ope= nvpn/ssl_mbedtls.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_openssl.= c
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify_mbedtls.c
M = src/openvpn/ssl_verify_openssl.c
M src/openvpn/tls_crypt.c
M src/open= vpn/tun.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/openvp= n/xkey_helper.c
M src/openvpnserv/common.c
M src/openvpnserv/interact= ive.c
M src/openvpnserv/service.h
M src/openvpnserv/validate.c
M t= ests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cr= yptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
38 files changed, = 288 insertions(+), 333 deletions(-)

git pull ssh://gerrit.openvpn=
.net:29418/openvpn refs/changes/47/547/2
diff --git a/src/openvpn/b=
uffer.c b/src/openvpn/buffer.c
index 66fd63f..3a8069c 10064= 4
--- a/src/openvpn/buffer.c
+++ b/src/open= vpn/buffer.c
@@ -279,32 +279,6 @@
retu= rn ret;
}

-
-/*
- * This is necess= ary due to certain buggy implementations of snprintf,
- * that don't guarantee null terminatio= n for size > 0.
- *<= /span>
- * Return false on ove= rflow.
- *
- * This functionality is duplicate= d in src/openvpnserv/common.c

- * Any modifications here should be done to the other place as well= .
- */
-
-bool
-o= penvpn_snprintf(char *str, size_t size, const char *format, ...)
= -{
- va_list arglist;
- int len =3D -1;
- if (size > 0)
- {
- len =3D vsnprintf(str, size, format, arglist);
- va_end(arglist);
- str[size - 1] = =3D 0;
- }- return (len >=3D 0 &= & len < size);
-= }
-
/*=
* write a string to the end of a buffer that was<= br> * truncated by buf_printf
diff --git a/src/openv= pn/buffer.h b/src/openvpn/buffer.h
index 7c2f75a..27c3199 1= 00644
--- a/src/openvpn/buffer.h
+++ b/src/= openvpn/buffer.h
@@ -448,19 +448,6 @@
*/<= /span>
bool buf_puts(struct buffer *buf, const char *str);=

-/*<= br>- * Like snprintf but guarante= es null termination for size > 0
- */
-bool= openvpn_snprintf(char *str, size_t size, const char *format, ...)-#ifdef __GNUC__
-#if __USE_MINGW_ANSI_STDIO
-__attribute__ ((format(gnu_prin= tf, 3, 4)))
-#else
-__attribute__ ((format(__p= rintf__, 3, 4)))
-#endi= f
-#endif
-;

-

/*
= * remove/add trailing characters
diff --git a/src/openvpn= /crypto.c b/src/openvpn/crypto.c
index 5d05cc4..207f145 100= 644
--- a/src/openvpn/crypto.c
+++ b/src/op= envpn/crypto.c
@@ -874,11 +874,11 @@

key_direction_state_init(&kds, key_direction);<= br>
- openvpn= _snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name);
+ snprintf(log_pref= ix, sizeof(log_prefix), "Outgoing %s", name);
= init_key_ctx(&ctx->encrypt, &key2->keys[kds.out_key], kt,
OPENVPN_OP_ENCRYPT, log_prefix);
- openvpn_s= nprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name);
+ snprintf(log_prefix= , sizeof(log_prefix), "Incoming %s", name);
= init_key_ctx(&ctx->decrypt, &key2->keys[kds.in_key], kt,
OPENVPN_OP_DECRYPT, log_prefix);

diff --git a/src/openvpn/crypto_mbedtls.c b/src/openv= pn/crypto_mbedtls.c
index 1a39752..c806719 100644--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn= /crypto_mbedtls.c
@@ -128,7 +128,7 @@
{
char prefix[256];

- if (!openvpn_snprintf(prefix, sizeof(p= refix), "%s:%d", func, line))
+ if (!snprintf(prefix, sizeof(prefix), "%s:%d&q= uot;, func, line))
{
return m= bed_log_err(flags, errval, func);
}
@@= -239,11 +239,11 @@
char header[1000+1] =3D { 0 };
char footer[1000+1] =3D { 0 };
- if (!openvpn_snprintf(head= er, sizeof(header), "-----BEGIN %s-----\n", name))
+ if (!snprintf(header, sizeof(h= eader), "-----BEGIN %s-----\n", name))

{
return false;
}
- if (!openvpn_snprintf(footer, size= of(footer), "-----END %s-----\n", name))
+ if (!snprintf(footer, sizeof(footer), &q= uot;-----END %s-----\n", name))
{
return false;

}
@@ -278,11 += 278,11 @@
char header[1000+1] =3D { 0 };
char footer[1000+1] =3D { 0 };


- if (!openvpn_snprintf(header, sizeof= (header), "-----BEGIN %s-----", name))
+ if (!snprintf(header, sizeof(header), &quo= t;-----BEGIN %s-----", name))
{
= return false;
}
- if (!openvpn_snprintf(footer, sizeof(footer), &q= uot;-----END %s-----", name))
+ if (!snprintf(footer, sizeof(footer), "-----END %s-= ----", name))
{
return f= alse;
}
diff --git a/src/openvpn/dns.c= b/src/openvpn/dns.c
index 7de3991..0539ca5 100644--- a/src/openvpn/dns.c
+++ b/src/openvpn/dns.c
@@ -349,11 +349,11 @@

i= f (j < 0)
{
- name_ok =3D openvpn_snprintf(name, sizeof(name), form= at, i);
+ name= _ok =3D snprintf(name, sizeof(name), format, i);
}
else
{
- name_ok =3D openvpn_snprintf(name, sizeof(n= ame), format, i, j);
= + name_ok =3D snprintf(name, sizeof(name), format, i, j);
= }

if (!name_ok)diff --git a/src/openvpn/env_set.c b/src/openvpn/env_set.cindex b13d01e..81ab59e 100644
--- a/src/openvpn/env_= set.c
+++ b/src/openvpn/env_set.c
@@ -259,7= +259,7 @@
setenv_counter(struct env_set *es, const char *= name, counter_type value)
{
char buf[= 64];
- openvpn_snpri= ntf(buf, sizeof(buf), counter_format, value);
+ snprintf(buf, sizeof(buf), counter_format, va= lue);
setenv_str(es, name, buf);
}

@@ -267,7 +267,7 @@
setenv= _int(struct env_set *es, const char *name, int value)
{
char buf[64];
- openvpn_snprintf(buf, sizeof(buf), "%d", value);
+ snprintf(buf, siz= eof(buf), "%d", value);
setenv_str(es, name,= buf);
}

@@ -275,7 +275,= 7 @@
setenv_long_long(struct env_set *es, const char *name= , long long value)
{
char buf[64];
- openvpn_snprintf(buf= , sizeof(buf), "%" PRIi64, (int64_t)value);
+ snprintf(buf, sizeof(buf), "%&qu= ot; PRIi64, (int64_t)value);
setenv_str(es, name, buf)= ;
}

@@ -310,7 +310,7 @@<= /span>
strcpy(tmpname, name);
while (NUL= L !=3D env_set_get(es, tmpname) && counter < 1000)
{

- ASSE= RT(openvpn_snprintf(tmpname, tmpname_len, "%s_%u", name, counter)= );
+ ASSERT(sn= printf(tmpname, tmpname_len, "%s_%u", name, counter));
= counter++;
}
if (c= ounter < 1000)
diff --git a/src/openvpn/error.c b/src/op= envpn/error.c
index 245a2d5..ec65d5e 100644
--- a/src/openvpn/error.c

+++ b/src/openvpn/error.c=
@@ -274,14 +274,14 @@

if (= (flags & M_ERRNO) && e)
{
- openvpn_snprintf(m2, ERR_BUF_S= IZE, "%s: %s (errno=3D%d)",
- m1, openvpn_strerror(e, crt_error,= &gc), e);
+ = snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)",
+ m1, openvpn_str= error(e, crt_error, &gc), e);

SWAP;
= }

if (flags & M_OPTER= R)
{
- openvpn_snprintf(m2, ERR_BUF_SIZE, "Options error: %s"= ;, m1);
+ snpr= intf(m2, ERR_BUF_SIZE, "Options error: %s", m1);
= SWAP;
}

@@ = -321,10 +321,10 @@
const struct virtual_output *vo= =3D msg_get_virtual_output();
if (vo)
<= span> {

- = openvpn_snprintf(m2, ERR_BUF_SIZE, "%s%s%s",
- prefix,=

- = prefix_sep,
- = m1);
+ snprintf(m2, ERR_BUF_SIZE, "%s%s%s",
+ pre= fix,
+ = prefix_sep,
+ = m1);
virtual_output_print(v= o, flags, m2);
}
}
= diff --git a/src/openvpn/init.c b/src/openvpn/init.c
= index f2ce926..bce2e09 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -359,7 +359,7 @@
char *out =3D malloc(len);
= check_malloc_return(out);

- openvpn_snprintf(out, len, "%s,%s,%s,%s&= quot;, ce->remote, ce->remote_port, proto, status);
+ snprintf(out, len, "%s,%= s,%s,%s", ce->remote, ce->remote_port, proto, status); *remote =3D out;
}
= else
diff --git a/src/openvpn/manage.c b/src/openvpn/mana= ge.c
index 43c5507..89591ea 100644
--- a/sr= c/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -515,8 +515,8 @@

char out[32];
=
/* do in a roundabout way to work around possible min= gw or mingw-glibc bug */
+ snprintf(in, sizeof(in), counter_format, man->persist.bytes= _in + dco_read_bytes);
- openvpn_snprintf(in, sizeof(in), counter_format, *byt= es_in_total);
- open= vpn_snprintf(out, sizeof(out), counter_format, *bytes_out_total);+ snprintf(in, sizeof(in), = counter_format, *bytes_in_total);
+ snprintf(out, sizeof(out), counter_format, *bytes_out_tot= al);
msg(M_CLIENT, ">BYTECOUNT_CLI:%lu,%s,%s&q= uot;, mdac->cid, in, out);
mdac->bytecount_last_= update =3D now;
}
diff --git a/src/openvpn= /options.c b/src/openvpn/options.c
index 768332d..a9a44ba 1= 00644
--- a/src/openvpn/options.c
+++ b/src= /openvpn/options.c
@@ -1427,7 +1427,7 @@
= for (int i =3D 1; i <=3D opt_max; ++i)
{<= br> char name[32];
- openvpn_snprintf(name, sizeof(name), "foreign_optio= n_%d", i);
+ = snprintf(name, sizeof(name), "foreign_option_%d", i);<= br>
const char *env_str =3D env_set_get(es,= name);
const char *value =3D strchr(env_str, '= ;=3D') + 1;
@@ -1482,7 +1482,7 @@
= while (o->foreign_option_index < opt_max)
{
char name[32];
- openvpn_snprintf(name, sizeof(name), "foreign_op= tion_%d", opt_max--);
+ snprintf(name, sizeof(name), "foreign_option_%d", = opt_max--);
setenv_del(es, name);
= }
}
@@ -5671,8 +5671,8 @@
<= span> #ifndef ENABLE_SMALL

{
= char script_name[100];
= - openvpn_snprintf(script_name, sizeof(script_name),
- "--%s s= cript", type);

+= snprintf(script_name, sizeof(script_name),
+ "--%s script", ty= pe);

if (check_cmd_access(*scrip= t, script_name, (in_chroot ? options->chroot_dir : NULL)))
{

diff --git a/src/openvpn/pkcs11.c b/src/openv= pn/pkcs11.c
index 35a02c2..418f6bb 100644
-= -- a/src/openvpn/pkcs11.c
+++ b/src/openvpn/pkcs11.c=
@@ -201,7 +201,7 @@
CLEAR(token_resp);
token_resp.defined =3D false;
token_re= sp.nocache =3D true;
- = openvpn_snprintf(
= + snprintf(
token_resp.username,
sizeof(token_resp.username),

"Plea= se insert %s token",
@@ -245,7 +245,7 @@

ASSERT(token!=3DNULL);
- openvpn_snprintf(prompt, s= izeof(prompt), "%s token", token->label);
+ snprintf(prompt, sizeof(prompt), &qu= ot;%s token", token->label);

= token_pass.defined =3D false;
token_pass.nocache =3D = true;
@@ -719,7 +719,7 @@

id_resp.defined =3D false;

id_resp.nocac= he =3D true;
- o= penvpn_snprintf(
+ = snprintf(
id_resp.username,
sizeof(id_resp.username),

&quo= t;Please specify PKCS#11 id to use"
diff --git a/src/o= penvpn/platform.c b/src/openvpn/platform.c
index 9853dac..3= d9d59e 100644
--- a/src/openvpn/platform.c
= +++ b/src/openvpn/platform.c
@@ -564,9 +564,9 @@
= {
++attempts;
<= br>- if (!openvpn_snprintf= (fname, sizeof(fname), fname_fmt, max_prefix_len,
- prefix, (unsigned= long) get_random(),
- = (unsigned long) get_random()))
+ if (!snprintf(fname, sizeof= (fname), fname_fmt, max_prefix_len,

+ prefix, (unsigned long) get_random(),=
+ = (unsigned long) get_random()))
{
msg(M_WARN, "ERROR: temporary filename too long");=

return NULL;
diff --git a/src= /openvpn/plugin.c b/src/openvpn/plugin.c
index 2ad459c..944= ce94 100644
--- a/src/openvpn/plugin.c
+++ = b/src/openvpn/plugin.c
@@ -260,7 +260,7 @@
= {
char full[PATH_MAX];

- openvpn_snprintf(f= ull, sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so_pathname);
+ snprintf(full,= sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so_pathname);=
p->handle =3D dlopen(full, RTLD_NOW);
}

else
@@ -409,7 +409,7 @@

gc_init(&gc);
= msg_fmt =3D gc_malloc(ERR_BUF_SIZE, false, &gc);
- openvpn_snprintf(msg_fmt, ERR_= BUF_SIZE, "PLUGIN %s: %s", name, format);
+ snprintf(msg_fmt, ERR_BUF_SIZE, &= quot;PLUGIN %s: %s", name, format);
x_msg_va(= msg_flags, msg_fmt, arglist);

gc= _free(&gc);
diff --git a/src/openvpn/pool.c b/src/openv= pn/pool.c
index f706c1a..e3c3708 100644
---= a/src/openvpn/pool.c
+++ b/src/openvpn/pool.c
@@ -766,7 +766,7 @@

ifconfig_pool_handle h;
in_addr_t local, remote;
ch= ar buf[256];
- o= penvpn_snprintf(buf, sizeof(buf), "common-name-%d", i);+ snprintf(buf, sizeof(= buf), "common-name-%d", i);
#ifdef DUP_CN=
cn =3D NULL;
#else
diff= --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index 5c= 1cdcb..ba3d87c 100644
--- a/src/openvpn/proxy.c
<= span>+++ b/src/openvpn/proxy.c

@@ -582,9 +582,9 @@ {
if (p->options.custom_headers[i]= .content)
{
- openvpn_snprintf(buf, sizeof(buf), "%s: %s&= quot;,
- = p->options.custom_headers[i].name,
- p->options.= custom_headers[i].content);
+ snprintf(buf, sizeof(buf), "%s: %s",+ p->o= ptions.custom_headers[i].name,
+ p->options.custom_headers[i].content);
if (!strcasecmp(p->options.custom_headers[i]= .name, "Host"))
{
= host_header_sent =3D true;
@@ -592,8 +592,8 = @@
}
else
{

- = openvpn_snprintf(buf, sizeof(buf), "%s",
- p->options.= custom_headers[i].name);
+ snprintf(buf, sizeof(buf), "%s",
+ p->options.= custom_headers[i].name);

if (!strncasecmp(p-&g= t;options.custom_headers[i].name, "Host:", 5))
= {
host_header_sent =3D true;
@@ -609,7 +609,7 @@

if= (!host_header_sent)
{
- openvpn_snprintf(buf, sizeof(buf), "Host= : %s", host);
+ = snprintf(buf, sizeof(buf), "Host: %s", host);
msg(D_PROXY, "Send to HTTP proxy: '%s'", buf= );

if (!send_line_crlf(sd, buf))
= {
@@ -620,8 +620,8 @@
/* send = User-Agent string if provided */
if (p->options.use= r_agent)
{
- openvpn_snprintf(buf, sizeof(buf), "User-Agent: %s&q= uot;,
- = p->options.user_agent);
+ snprintf(buf, sizeof(buf), "User-Agent: %s&quo= t;,
+ = p->options.user_agent);
msg(D_PROXY, "Sen= d to HTTP proxy: '%s'", buf);
if (!se= nd_line_crlf(sd, buf))
{
@@ -667,1= 0 +667,10 @@
else
{
/* format HTTP CONNECT message */

- openvpn_snprintf(buf, sizeof(buf), "CO= NNECT %s:%s HTTP/%s",
- host,
- port,
- p->options.http_version)= ;
+ snprintf(b= uf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
+ host,
+ port,
+ p->options.http= _version);


msg(D_PROXY, "Se= nd to HTTP proxy: '%s'", buf);

@@ -692,8 +692,8 @@

break;

case HTTP_AUTH_BASIC:
- openvpn_snprintf(buf, si= zeof(buf), "Proxy-Authorization: Basic %s",
- username_p= assword_as_base64(p, &gc));
+ snprintf(buf, sizeof(buf), "Proxy-Authoriz= ation: Basic %s",
- openvpn_snprintf(buf, = sizeof(buf), "Proxy-Connection: Keep-Alive");
+ snprintf(buf, sizeof(bu= f), "Proxy-Connection: Keep-Alive");
= if (!send_line_crlf(sd, buf))
{
goto error;
= }

-= openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorizatio= n: NTLM %s",
- = ntlm_phase_1(p, &gc));
+ snprintf(buf, sizeof(bu= f), "Proxy-Authorization: NTLM %s",
+ ntlm_phase_1(p, &gc)= );
msg(D_PROXY, "Attempting NTLM Prox= y-Authorization phase 1");
dmsg(D_SHO= W_KEYS, "Send to HTTP proxy: '%s'", buf);
if (!send_line_crlf(sd, buf))

@@ -773,7 += 773,7 @@

char get[80];
CLEAR(buf2);
- openvpn_snprintf(get, sizeof(get), &= quot;%%*s NTLM %%%zus", sizeof(buf2) - 1);
+ snprintf(get, sizeof(get), &quo= t;%%*s NTLM %%%zus", sizeof(buf2) - 1);
= nparms =3D sscanf(buf, get, buf2);

= /* check for "Proxy-Authenticate: NTLM TlRM..." */<= /span>
@@ -795,10 +795,10 @@
/* now s= end the phase 3 reply */

/* = format HTTP CONNECT message */
- openvpn_snprintf(buf, sizeof(buf), "CONNECT %s:%s= HTTP/%s",
- = host,
- port,
- p->options.http_version= );
+ snpri= ntf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
+ host,
<= span style=3D"color: hsl(120, 100%, 40%);">+ port,
+ p-&= gt;options.http_version);

ms= g(D_PROXY, "Send to HTTP proxy: '%s'", buf);

@@ -809,7 +809,7 @@
}


/* keep-alive connection */
- openvpn_snpr= intf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive");+ snprintf(buf, siz= eof(buf), "Proxy-Connection: Keep-Alive");
= if (!send_line_crlf(sd, buf))
{<= br> goto error;
@@ -829,7 +829,7 @@
msg(D_PROXY, "NTLM Proxy-Authoriza= tion phase 3 failed: received corrupted data from proxy server");
goto error;
= }
- o= penvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",= np3);
+ = snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s", np3= );
}

= msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
@@ -899,15 +899,15 @@


/* build the digest response */
- openvpn_snprintf(uri,= sizeof(uri), "%s:%s",

- host,
- port);<= br>+ snprintf(ur= i, sizeof(uri), "%s:%s",
+ host,
+ port);
=
if (opaque)
= {
const int len =3D strlen(opaque)= +16;
opaque_kv =3D gc_malloc(len, fals= e, &gc);
- = openvpn_snprintf(opaque_kv, len, ", opaque=3D\"%s\&quo= t;", opaque);
+ = snprintf(opaque_kv, len, ", opaque=3D\"%s\&quo= t;", opaque);
}

DigestCalcHA1(algor,
@@ -928,= 10 +928,10 @@
response)= ;

/* format HTTP CONNECT= message */
- = openvpn_snprintf(buf, sizeof(buf), "%s %s HTTP/%s",<= br>- = http_method,
- = uri,
- p->options.http_version);
+ snprin= tf(buf, sizeof(buf), "%s %s HTTP/%s",
+ http_method,+ uri,=
+ = p->options.http_version);

= msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);=

@@ -948,21 +948,22 @@
= }

/* send= digest response */
- = int sret =3D openvpn_snprintf(buf, sizeof(buf), "Proxy-A= uthorization: Digest username=3D\"%s\", realm=3D\"%s\",= nonce=3D\"%s\", uri=3D\"%s\", qop=3D%s, nc=3D%s, cnonc= e=3D\"%s\", response=3D\"%s\"%s",
- = username,
- = realm,
- nonce,
- = uri,
- qop,
- = nonce_count,
- = cnonce,
- response,=
- = opaque_kv
- );
+ int sret =3D snprintf= (buf, sizeof(buf), "Proxy-Authorization: Digest username=3D\"%s\&= quot;, realm=3D\"%s\", nonce=3D\"%s\", uri=3D\"%s\= ", qop=3D%s, nc=3D%s, cnonce=3D\"%s\", response=3D\"%s\= "%s",
+ = username,
+ realm,
= + = nonce,
+ = uri,
+ qop,
+ nonc= e_count,
+ = cnonce,
+ response,
+ = opaque_kv
+ = );
if (sret >= =3D sizeof(buf))
{
= goto error;
}
+

= msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
= if (!send_line_crlf(sd, buf))
= {
diff --git a/src/openvpn/ps.c b/src/openvpn/ps= .c
index 7d9f9b5..4ca3a12 100644
--- a/src/= openvpn/ps.c
+++ b/src/openvpn/ps.c
@@ -354= ,7 +354,7 @@
fnlen =3D strlen(journal_dir) + strl= en(t) + 2;
jfn =3D (char *) malloc(fnlen);<= br> check_malloc_return(jfn);
- openvpn_snprintf(jfn, fnlen, "%s/%s"= ;, journal_dir, t);
+= snprintf(jfn, fnlen, "%s/%s", journal_dir, t);
= dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin= %s -> %s", jfn, f);
fd =3D platform_open(= jfn, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
= if (fd !=3D -1)
diff --git a/src/openvpn/rou= te.c b/src/openvpn/route.c
index 909d6d2..68bbcfd 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/r= oute.c
@@ -1621,11 +1621,11 @@

= if (rgi)
{
- openvpn_snprintf(out, sizeof(out), "%s %s= %s dev %s", network, netmask, gateway, rgi->iface);
+ snprintf(out, sizeof(out),= "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
}
else
{
- openvpn_snprintf(ou= t, sizeof(out), "%s %s %s", network, netmask, gateway);+ snprintf(out, sizeof(= out), "%s %s %s", network, netmask, gateway);
= }
bool ret =3D management_android_control(management= , "ROUTE", out);
status =3D ret ? RTA_SUCCES= S : RTA_ERROR;
@@ -2000,7 +2000,7 @@
#elif= defined (TARGET_ANDROID)
char out[64];

- openvpn_snprin= tf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device)= ;
+ snprintf(out, = sizeof(out), "%s/%d %s", network, r6->netbits, device);=

status =3D management_android_control(mana= gement, "ROUTE6", out);

diff --= git a/src/openvpn/run_command.h b/src/openvpn/run_command.h
index 52ab115..ccad307 100644

--- a/src/openvpn/run_comman= d.h
+++ b/src/openvpn/run_command.h
@@ -66,= 8 +66,8 @@
{
char msg[256];
- openvpn_s= nprintf(msg, sizeof(msg),
- "WARNING: Failed running command (%s)", = hook);
+ snprintf(= msg, sizeof(msg),
+ = "WARNING: Failed running command (%s)", hook);<= br> return openvpn_execve_check(a, es, flags | S_SCRIPT, msg);
}

diff --git a/src/openvpn= /socket.c b/src/openvpn/socket.c
index d2b82d5..24d1276 100= 644
--- a/src/openvpn/socket.c
+++ b/src/op= envpn/socket.c
@@ -2983,11 +2983,11 @@
= case AF_INET:
if (flags & SA_IP_PORT)=
{
- openvpn_snprintf(name_buf, sizeof(name_buf), &quo= t;%s_ip", name_prefix);
+ snprintf(name_buf, sizeof(name_buf), "%s_ip&q= uot;, name_prefix);
}
= else
{
- openvpn_snprintf(name_buf, sizeof(name_b= uf), "%s", name_prefix);
+ snprintf(name_buf, sizeof(name_buf), "%= s", name_prefix);
}

inet_ntop(AF_INET, &addr->addr.in4.sin_add= r, buf, sizeof(buf));
@@ -2995,7 +2995,7 @@

if ((flags & SA_IP_PORT) && add= r->addr.in4.sin_port)
{
- openvpn_snprintf(name_buf= , sizeof(name_buf), "%s_port", name_prefix);
+ snprintf(name_buf, sizeo= f(name_buf), "%s_port", name_prefix);
= setenv_int(es, name_buf, ntohs(addr->addr.in4.sin_port)); }
break;
= @@ -3006,19 +3006,19 @@
struct in_addr ia;=
memcpy(&ia.s_addr, &addr->addr= .in6.sin6_addr.s6_addr[12],
sizeof(= ia.s_addr));
- = openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name= _prefix);
+ = snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);=
inet_ntop(AF_INET, &ia, buf, sizeof(b= uf));
}
else
{
- openvpn_snprintf(name_buf, sizeof(name_buf), "%s_= ip6", name_prefix);
+ snprintf(name_buf, sizeof(name_buf), "%s_ip6"= ;, name_prefix);
inet_ntop(AF_INET6, &= addr->addr.in6.sin6_addr, buf, sizeof(buf));
= }
setenv_str(es, name_buf, buf);
<= span>

if ((flags & SA_IP_PORT) &&= addr->addr.in6.sin6_port)
{
- openvpn_snprintf(nam= e_buf, sizeof(name_buf), "%s_port", name_prefix);

+ snprintf(name_buf, = sizeof(name_buf), "%s_port", name_prefix);

= setenv_int(es, name_buf, ntohs(addr->addr.in6.sin6_port));
}
break;
= diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c
index b046910..8b8c01a 100644

--- a/src/openvpn/socks.c
+++ b/src/openvpn/socks.c
@@ -109,9 +109,10 = @@
"Authentication not possible.");<= /span>
goto cleanup;
}
- int sret =3D openvpn_snprintf(t= o_send, sizeof(to_send), "\x01%c%s%c%s",

- (int) strlen(c= reds.username), creds.username,
- (int) strlen(creds.password), cre= ds.password);
+
+ int sret =3D snprintf= (to_send, sizeof(to_send), "\x01%c%s%c%s",
+ (int) strlen(cred= s.username), creds.username,
+ (int) strlen(creds.password), creds.passwo= rd);
ASSERT(sret <=3D sizeof(to_send));
<= span>

size =3D send(sd, to_send, strlen(to_send), MSG= _NOSIGNAL);
diff --git a/src/openvpn/ssl_mbedtls.c b/src/op= envpn/ssl_mbedtls.c
index 0730d25..b0303b6 100644--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ss= l_mbedtls.c
@@ -1531,16 +1531,16 @@
ch= ar s2[256];

s1[0] =3D s2[0] =3D 0;
- openvpn_snprintf(s1= , sizeof(s1), "%s %s, cipher %s",
- prefix,
- mbedtls_ssl_get_version(k= s_ssl->ctx),
- = mbedtls_ssl_get_ciphersuite(ks_ssl->ctx));
+ snprintf(s1, sizeof(s1), "= ;%s %s, cipher %s",

+ prefix,
+ mbedtls_ssl_get_version(ks_ssl->ctx),
+ mbedtls_ssl_get_cipher= suite(ks_ssl->ctx));


cert =3D mbe= dtls_ssl_get_peer_cert(ks_ssl->ctx);
if (cert !=3D = NULL)
{
- openvpn_snprintf(s2, sizeof(s2), ", %u bit key",
- = (unsigned int) mbedtls_pk_get_bitlen(&cert->pk));
+ snprintf(s2, sizeof(s2), &qu= ot;, %u bit key",
- = ciphername));
+ ASSERT(snprintf(ncp_ciphers, newlen, "%s:%s", = o->ncp_ciphers,
+ = ciphername));
o->ncp_ciphers =3D= ncp_ciphers;
}

diff --g= it a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
= index 6f29c3d..16a8c15 100644
--- a/src/openvpn/ssl_openssl= .c
+++ b/src/openvpn/ssl_openssl.c
@@ -1774= ,7 +1774,7 @@
if (!biofp)
{
char fn[256];
- openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log&qu= ot;, pid, biofp_toggle);
+ snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp= _toggle);
biofp =3D fopen(fn, "w");
ASSERT(biofp);
biofp_last_ope= n =3D time(NULL);
@@ -2116,8 +2116,8 @@
#e= ndif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */
= }

- = openvpn_snprintf(buf, buflen, "%d bits %s%s",
- EVP_PKEY_bits(pkey= ), type, curve);
+ = snprintf(buf, buflen, "%d bits %s%s",
+ EVP_PKEY_bits(pkey), type, curve)= ;
}

/**
@@ -2137,12 +2137,12 @@

int signature_nid =3D X509_ge= t_signature_nid(cert);
if (signature_nid !=3D 0)
{
- = openvpn_snprintf(sig, sizeof(sig), ", signature: %s",<= br>- OBJ_= nid2sn(signature_nid));
+ snprintf(sig, sizeof(sig), ", signature: %s",<= br>+ OBJ_nid2sn= (signature_nid));
}

- openvpn_snprintf(buf, buflen, &quo= t;, peer certificate: %s%s",
- pkeybuf, sig);
+ snprintf(buf, buflen, ", peer certific= ate: %s%s",
+ = pkeybuf, sig);

EVP_PKEY_fr= ee(pkey);
}
@@ -2160,8 +2160,8 @@ char pkeybuf[128] =3D { 0 };
print_pkey_d= etails(pkey, pkeybuf, sizeof(pkeybuf));

- openvpn_snprintf(buf, buflen, "= ;, peer temporary key: %s",
- pkeybuf);
+ snprintf(buf, buflen, ", peer temporary key:= %s",
+ = pkeybuf);

EVP_PKEY_free(pkey);
}
@@ -2237,8 +2237,8 @@
= return;
}

- openvpn_snprintf(buf, buflen, ", = peer signing digest/type: %s %s",
- peer_sig, peer_sig_type);
<= span style=3D"color: hsl(120, 100%, 40%);">+ snprintf(buf, buflen, "= ;, peer signing digest/type: %s %s",

+ peer_sig, peer_sig_type);
}



@@ -2261,11 +2261,= 11 @@

s1[0] =3D s2[0] =3D s3[0] =3D = s4[0] =3D 0;
ciph =3D SSL_get_current_cipher(ks_ssl-&g= t;ssl);
- openvpn_sn= printf(s1, sizeof(s1), "%s %s, cipher %s %s",
- prefix,
- SSL_get_versi= on(ks_ssl->ssl),

- = SSL_CIPHER_get_version(ciph),
- SSL_CIPHER_get_name(ciph));=
+ snprintf(s1, si= zeof(s1), "%s %s, cipher %s %s",
+ prefix,
+ SSL_get_version(ks_ssl->ssl),
+ SSL_CIPHER_g= et_version(ciph),
+ = SSL_CIPHER_get_name(ciph));
X509 *cert =3D = SSL_get_peer_certificate(ks_ssl->ssl);

if (cert)

diff --git a/src/openvpn/ssl_verify.c b/src= /openvpn/ssl_verify.c
index c7d7799..ec7ff23 100644<= br>--- a/src/openvpn/ssl_verify.c
+++ b/src/openvpn/s= sl_verify.c
@@ -421,12 +421,12 @@
}

/* export subject name string as envir= onmental variable */
- = openvpn_snprintf(envname, sizeof(envname), "tls_id_%d", cert_d= epth);
+ snprintf(= envname, sizeof(envname), "tls_id_%d", cert_depth);
setenv_str(es, envname, subject);


#if 0

/* export common name string as environmental = variable */
- openvp= n_snprintf(envname, sizeof(envname), "tls_common_name_%d", cert_d= epth);
+ snprintf(= envname, sizeof(envname), "tls_common_name_%d", cert_depth);
setenv_str(es, envname, common_name);
#en= dif

@@ -435,24 +435,24 @@
struct buffer sha1 =3D x509_get_sha1_fingerprint(peer_cert, &= gc);

struct buffer sha256 =3D x509_get_sha256_fing= erprint(peer_cert, &gc);

- openvpn_snprintf(envname, sizeof(envname),= "tls_digest_%d", cert_depth);
+ snprintf(envname, sizeof(envname), "tls_d= igest_%d", cert_depth);
setenv_str(es, envnam= e,
format_hex_ex(BPTR(&sha1), BLEN(= &sha1), 0, 1, ":", &gc));

- openvpn_snprintf(envname, s= izeof(envname), "tls_digest_sha256_%d",

- cert_depth);+ snprintf(envname, siz= eof(envname), "tls_digest_sha256_%d",
+ cert_depth);
= setenv_str(es, envname,
format_= hex_ex(BPTR(&sha256), BLEN(&sha256), 0, 1, ":", &gc))= ;
}

/* export s= erial number as environmental variable */
serial =3D b= ackend_x509_get_serial(peer_cert, &gc);
- openvpn_snprintf(envname, sizeof(envname), "= tls_serial_%d", cert_depth);
+ snprintf(envname, sizeof(envname), "tls_serial_%d&qu= ot;, cert_depth);
setenv_str(es, envname, serial);

/* export serial number in hex as envir= onmental variable */
serial =3D backend_x509_get_seria= l_hex(peer_cert, &gc);
- openvpn_snprintf(envname, sizeof(envname), "tls_serial_hex_%d= ", cert_depth);
= + snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert= _depth);
setenv_str(es, envname, serial);

gc_free(&gc);
@@ -569,7 +569= ,7 @@
goto cleanup;
}<= br>
- if (!op= envpn_snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR,= serial))
+ if (!s= nprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR, serial= ))
{
msg(D_HANDSHAKE, "V= ERIFY CRL: filename overflow");
goto cleanup;=
@@ -938,9 +938,9 @@
if (!chec= k_auth_pending_method(multi->peer_info, pending_method))
{

char buf[128];
<= span style=3D"color: hsl(0, 100%, 40%);">- openvpn_snprintf(= buf, sizeof(buf),

- = "Authentication failed, required pending = auth "
- = "method '%s' not supported", pendi= ng_method);
+ = snprintf(buf, sizeof(buf),
+ "Authentication failed, requir= ed pending auth "
- = if (ret <=3D 0 && !openvpn_snprintf(errstr, sizeof(errstr),<= /span>
- = "Could not retrieve error string, flags=3D%" = PRIx32, *flags))
+ = if (ret <=3D 0 && !snprintf(errstr, sizeof(errstr),<= br>+ = "Could not retrieve error string, flags=3D%" PRIx32, *flag= s))
{
errstr[0] =3D &= #39;\0';
}
@@ -307,7 +307,7 @@=
name_expand_size =3D 64 + strlen(name);
name_expand =3D (char *) malloc(name_expand_size);

= check_malloc_return(name_expand);
- openvpn_snprintf(name_expand, name_expand_size, "= X509_%d_%s", depth, name);
+ snprintf(name_expand, name_expand_size, "X509_%d_%s&qu= ot;, depth, name);
setenv_str(es, name_expand, value);=
free(name_expand);
}
@@ -431,13 +431,13 @@


if (0 =3D= =3D mbedtls_oid_get_attr_short_name(&name->oid, &shortname) )
{
- = cert_depth, shortname);
+ snprintf(name_expand, sizeof(name_exp= and), "X509_%d_%s",
+ cert_depth, shortname);
= }
else
{
<= span style=3D"color: hsl(0, 100%, 40%);">- openvpn_snprintf(name= _expand, sizeof(name_expand), "X509_%d_\?\?",

- cert_depth);=
+ snprint= f(name_expand, sizeof(name_expand), "X509_%d_\?\?",
+ cert_depth);=

}

for = (i =3D 0; i < name->val.len; i++)
diff --git a/src/op= envpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c
index ec3a7cf..7d41d4a 100644
--- a/src/openvpn/ssl_veri= fy_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c<= br>@@ -279,7 +279,7 @@
gc_free(&gc);=
return FAILURE;
}
- openvpn_snprintf= (common_name, cn_len, "0x%s", serial);
+ snprintf(common_name, cn_len, "0x= %s", serial);
gc_free(&gc);
}

else
@@ -454,7 +454,7 @@

name_expand_size =3D 64 + strlen(name);
= name_expand =3D (char *) malloc(name_expand_size);
= check_malloc_return(name_expand);
- openvpn_snprintf(name_expand, name_expand_size, "X509= _%d_%s", depth, name);
+ snprintf(name_expand, name_expand_size, "X509_%d_%s",= depth, name);
setenv_str(es, name_expand, value);
free(name_expand);
}
@@ = -597,8 +597,8 @@
name_expand_size =3D 64 + strlen(= objbuf);
name_expand =3D (char *) malloc(name_expa= nd_size);
check_malloc_return(name_expand);=
- openvpn_snprintf(nam= e_expand, name_expand_size, "X509_%d_%s", cert_depth,
<= span style=3D"color: hsl(0, 100%, 40%);">- objbuf);=

+ snprintf(na= me_expand, name_expand_size, "X509_%d_%s", cert_depth,
= + objbuf);
string_mod(name_expand, CC_PRINT, CC_CRLF, '_'= );
string_mod((char *)buf, CC_PRINT, CC_CRLF, '= ;_');
setenv_str_incr(es, name_expand, (char *= )buf);
diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/t= ls_crypt.c
index 6ef1c7d..90fe6e9 100644
--= - a/src/openvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
@@ -574,8 +574,8 @@
}
=
char metadata_type_str[4] =3D { 0 }; /* Max value: 25= 5 */
- openvpn_snpri= ntf(metadata_type_str, sizeof(metadata_type_str),
- "%i", (uint8_t) = metadata_type);
+ = snprintf(metadata_type_str, sizeof(metadata_type_str),
+ "%i", (uint8_t) m= etadata_type);
struct env_set *es =3D env_set_create(N= ULL);
setenv_str(es, "script_type", "tl= s-crypt-v2-verify");
setenv_str(es, "metadat= a_type", metadata_type_str);
diff --git a/src/openvpn/= tun.c b/src/openvpn/tun.c
index f550e9c..d01515d 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.= c
@@ -1114,8 +1114,8 @@
#elif defined(TARG= ET_ANDROID)
char out6[64];
- openvpn_snprintf(out6, size= of(out6), "%s/%d %d",
- ifconfig_ipv6_local, tt->netbits_ipv6, tu= n_mtu);
+ snprintf= (out6, sizeof(out6), "%s/%d %d",
+ ifconfig_ipv6_local, tt->netbits_ipv= 6, tun_mtu);
management_android_control(management, &q= uot;IFCONFIG6", out6);
#elif defined(TARGET_SOLARIS)<= /span>
argv_printf(&argv, "%s %s inet6 unplumb"= , IFCONFIG_PATH, ifname);
@@ -1362,8 +1362,8 @@
<= span> top =3D "undef";

}<= br>
- openvpn= _snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local,=
- ifconfi= g_remote_netmask, tun_mtu, top);
+ snprintf(out, sizeof(out), "%s %s %d %s", ifconf= ig_local,
+ = ifconfig_remote_netmask, tun_mtu, top);
management_= android_control(management, "IFCONFIG", out);

#elif defined(TARGET_SOLARIS)
@@ -1912,7 +1= 912,7 @@
*/
if (dev_node= )
{
- openvpn_snprintf(tunname, sizeof(tunname), "%s"= ;, dev_node);
+ = snprintf(tunname, sizeof(tunname), "%s", dev_node);<= br> }
else
= {
@@ -1926,10 +1926,10 @@
{
for (int i =3D 0; i < 256; ++i) {
- openvpn_snprintf(tunname, sizeof(tunname),- = "/dev/%s%d", dev, i);
- openvpn_snprintf(dynamic_name, sizeof(= dynamic_name),
- = "%s%d", dev, i);
+ snprintf(tunname, = sizeof(tunname),
+ = "/dev/%s%d", dev, i);
+ snprintf(dynamic_= name, sizeof(dynamic_name),
+ "%s%d", dev, i);
<= span> if ((tt->fd =3D open(tunname, O_RDWR)) > 0)=

{
= dynamic_opened =3D true;
@@ -1947,7 +1947,7 @@=
*/
else
{

- = openvpn_snprintf(tunname, sizeof(tunname), "/dev/%s", = dev);
+ = snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
<= span> }

}

= @@ -2002,8 +2002,8 @@
{
= for (int i =3D 0; i < 256; ++i)
{
- openvpn_snprintf(dynam= ic_name, sizeof(dynamic_name),

- "%s%d", dev, i);
= + snprintf(dynamic_n= ame, sizeof(dynamic_name),
+ "%s%d", dev, i);
= int ret =3D open_tun_dco(tt, ctx, dynamic_name);
= if (ret =3D=3D 0)
{
@@ -2519,7 +2519,7 @@

tt->actual_name =3D (char *= ) malloc(32);
check_malloc_return(tt->actual_name);=

- = openvpn_snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type= , ppa);
+ snprintf= (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
if (tt->type =3D=3D DEV_TYPE_TAP) {
@@ -3509,7 +3509,7 @@
= int i;
for (i =3D 0; i<99; i++)
{
- = openvpn_snprintf(tunname, sizeof(tunname), "/dev/tap%d", i);=
+ snprint= f(tunname, sizeof(tunname), "/dev/tap%d", i);
= if (access( tunname, F_OK ) < 0 && errno =3D=3D ENOENT= )
{
break;

@@ -3520,7 +3520,7 @@
msg( M_FAT= AL, "cannot find unused tap device" );
}=

- = openvpn_snprintf( dynamic_name, sizeof(dynamic_name), "tap%d"= ;, i );
+ snpr= intf( dynamic_name, sizeof(dynamic_name), "tap%d", i ); dev =3D dynamic_name;
}
else /* name given, sanity ch= eck */
@@ -3536,7 +3536,7 @@
m= sg( M_FATAL, "TAP device name must be '--dev tapNNNN'" );=
}

- openvpn_snprintf(tunname, sizeof(tunname), = "/dev/%s", dev);
+ snprintf(tunname, sizeof(tunname), "/dev/%s", dev)= ;
}

/* pre-exis= ting device?
@@ -3956,8 +3956,8 @@
= ADAPTER_KEY);
}
<= br>- openvpn_snprintf(unit= _string, sizeof(unit_string), "%s\\%s",
- ADAPTER_KEY, enum_name= );
+ snprintf(= unit_string, sizeof(unit_string), "%s\\%s",
+ ADAPTER_KEY, enum_name);=

status =3D RegOpenKeyEx(=
HKEY_LOCAL_MACHINE,
@@ -4098,9 +4098= ,9 @@
NETWORK_CONNECTIONS_KEY);
= }

- openvpn_snprintf(connection_string, sizeof(connection_= string),
- = "%s\\%s\\Connection",
- NETWORK_CONNECTIONS_KEY, enu= m_name);
+ snp= rintf(connection_string, sizeof(connection_string),
+ "%s\\%s\\Connection= ",
+ = NETWORK_CONNECTIONS_KEY, enum_name);

status =3D RegOpenKeyEx(
HKEY_LOCAL_= MACHINE,
@@ -4984,7 +4984,7 @@
DWORD i= ndex;
ULONG aindex;
wchar_t wbuf[= 256];
- openvpn_swpr= intf(wbuf, SIZE(wbuf), L"\\DEVICE\\TCPIP_%hs", guid);
<= span style=3D"color: hsl(120, 100%, 40%);">+ swprintf(wbuf, SIZE(wbuf), = L"\\DEVICE\\TCPIP_%hs", guid);
if (GetAdapte= rIndex(wbuf, &aindex) !=3D NO_ERROR)
{
<= span> index =3D TUN_ADAPTER_INDEX_INVALID;
@@ -5164= ,10 +5164,10 @@
}

/* Open Windows TAP-Windows adapter */
- openvpn_snprintf(device_path, sizeof(de= vice_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,

- TA= P_WIN_SUFFIX);
+ = snprintf(device_path, sizeof(device_path), "%s%s%s",+ USERMODEDEVI= CEDIR,
+ = device_guid,
+ = TAP_WIN_SUFFIX);

h= and =3D CreateFile(
device_path,
@@ -5208,10 +5208,10 @@
}
=
/* Open Windows TAP-Windows adapter */=
- openvpn_snprintf= (device_path, sizeof(device_path), "%s%s%s",
- USERMODEDEVIC= EDIR,
- = device_guid,
- TAP_WIN_SUFFIX);
+ snprintf(device_path, sizeof(devi= ce_path), "%s%s%s",
+ USERMODEDEVICEDIR,
+ device_guid,
<= span style=3D"color: hsl(120, 100%, 40%);">+ TAP_WIN_SU= FFIX);

hand =3D CreateFile(<= /span>
device_path,
@@ -6607,10 += 6607,10 @@
else
{
/* Open TAP-Windows */

- openvpn_snprintf(tuntap_device_path, sizeof(tuntap_devic= e_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,- TAP_W= IN_SUFFIX);
+ = snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s"= ,
+ U= SERMODEDEVICEDIR,
+ = device_guid,
+ TAP_WIN_SUFFIX);
path =3D= tuntap_device_path;
}

diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c
i= ndex 27d82c5..98955ba 100644
--- a/src/openvpn/win32.c

+++ b/src/openvpn/win32.c
@@ -885,8 +885,8 @@
char force_path[256];
char *sysroo= t =3D get_win_sys_path();

- if (!openvpn_snprintf(force_path, sizeof(force_pa= th), "PATH=3D%s\\System32;%s;%s\\System32\\Wbem",
- sysroot, sy= sroot, sysroot))

+ = if (!snprintf(force_path, sizeof(force_path), "PATH=3D%s\\System32;%s= ;%s\\System32\\Wbem",
+ sysroot, sysroot, sysroot))
{=
msg(M_WARN, "env_block: default path truncat= ed to %s", force_path);
}
@@ -148= 3,26 +1483,11 @@
}

bool=
-openvpn_swprintf(wcha= r_t *const str, const size_t size, const wchar_t *const format, ...)=
-{
- va_list arglist;
- int len =3D -1;
- if (size > 0)
- {
- va_start(arglist, format);
- len =3D vswprintf(str, size, format, arglist);<= /span>
- va_end(arglist= );
- str[size - = 1] =3D L'\0';
-= }
- return (len = >=3D 0 && len < size);
-}
-
-bool
get_= openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size)
{

WCHAR reg_path[256];
HKEY h= key;
- openvpn_swpri= ntf(reg_path, _countof(reg_path), L"SOFTWARE\\" PACKAGE_NAME);
+ swprintf(reg_path,= _countof(reg_path), L"SOFTWARE\\" PACKAGE_NAME);

LONG status =3D RegOpenKeyExW(HKEY_LOCAL_MACHINE, r= eg_path, 0, KEY_READ, &hkey);
if (status !=3D ERRO= R_SUCCESS)
@@ -1528,7 +1513,7 @@
/= * if we cannot find installation path from the registry,
= * use Windows directory as a fallback
*/<= /span>
- openvpn_swprin= tf(install_path, _countof(install_path), L"%ls", ssl_fallback_dir= );
+ swprintf(= install_path, _countof(install_path), L"%ls", ssl_fallback_dir);<= /span>
}

if ((install_= path[wcslen(install_path) - 1]) =3D=3D L'\\')
@@ -1= 553,7 +1538,7 @@
if (size =3D=3D 0)
{

WCHAR val[MAX_PATH] =3D {0};
- openvpn_swprin= tf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, ossl_env[i= ].value);
+ = swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, os= sl_env[i].value);
_wputenv_s(ossl_env[i].name,= val);
}
}
di= ff --git a/src/openvpn/win32.h b/src/openvpn/win32.h
index = 974fe02d..fd75992 100644
--- a/src/openvpn/win32.h+++ b/src/openvpn/win32.h
@@ -319,14 +319,6 @@
int
openvpn_execve(const struct argv *a, cons= t struct env_set *es, const unsigned int flags);
-/*
- * openvpn_swprintf() is currently only used by W= indows code paths
- * a= nd when enabled for all platforms it will currently break older
<= span style=3D"color: hsl(0, 100%, 40%);">- * OpenBSD versions lacking vswpr= intf(3) support in their libc.

- */
-bool
-openvpn_swprintf(wchar_t *= const str, const size_t size, const wchar_t *const format, ...);
= -
/* Sleep that = can be interrupted by signals and exit event */
void win32= _sleep(const int n);

diff --git a/src/ope= nvpn/xkey_helper.c b/src/openvpn/xkey_helper.c
index c80332= 3..283c95d 100644
--- a/src/openvpn/xkey_helper.c+++ b/src/openvpn/xkey_helper.c
@@ -205,7 +205,7 @@<= /span>
}
else
= {
- o= penvpn_snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=3D%s", a= lg.mdname);
+ = snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=3D%s", alg.= mdname);
}
}
= else if (!strcmp(alg.keytype, "ED448") || !strcmp(alg.keytyp= e, "ED25519"))
@@ -229,8 +229,8 @@
/* For undigested message, add hashalg=3Ddigest parameter */
else
{
- openvpn_snprintf(alg_str, sizeo= f(alg_str), "%s,hashalg=3D%s",
- "RSA_PKCS1_PADDING&quo= t;, alg.mdname);
+ = snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s",
+ &= quot;RSA_PKCS1_PADDING", alg.mdname);
}
}
else if (!strcmp(alg.padmode, "= none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
@@ -240,8 +240,8 @@

}
else if= (!strcmp(alg.padmode, "pss") && (flags & MF_EXTERNAL= _KEY_PSSPAD))
{
- openvpn_snprintf(alg_str, sizeof(alg_str), "%s,= hashalg=3D%s,saltlen=3D%s",
- "RSA_PKCS1_PSS_PADDING", alg.= mdname, alg.saltlen);
+ snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s,saltlen= =3D%s",
+ = "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen);

}
else
{<= br>diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c
index bd0a484..96bf800 100644
--- a/src/open= vpnserv/common.c
+++ b/src/openvpnserv/common.c
<= span>@@ -27,36 +27,6 @@

LPCTSTR service_instance =3D TEXT(= "");
static wchar_t win_sys_path[MAX_PATH];

-/*
- * These are necessary due = to certain buggy implementations of (v)snprintf,
- * that don't guarantee null termination for= size > 0.
- */
-BOOL
-openvpn_vswprintf(LPTSTR str, size_t size, = LPCTSTR format, va_list arglist)
-{
- int l= en =3D -1;
- if (siz= e > 0)
- {=
- len =3D vswprintf_s(= str, size, format, arglist);
- str[size - 1] =3D 0;
- }
- = return (len >=3D 0 && (size_t)len < size);
-}
-
-BOOL=
-openvpn_swprintf(LPTS= TR str, size_t size, LPCTSTR format, ...)
-{
-= va_list arglist;
- = BOOL res =3D FALSE;
= - if (size > 0)
-= {
- va_start= (arglist, format);
- = res =3D openvpn_vswprintf(str, size, format, arglist);
- va_end(arglist);

- }

- return res;
-}
-<= /span>
static DWORD
GetRegString(HKEY key, LPCTS= TR value, LPTSTR data, DWORD size, LPCTSTR default_value)
= {
@@ -66,7 +36,7 @@
if (status =3D=3D = ERROR_FILE_NOT_FOUND && default_value)
{
size_t len =3D size/sizeof(data[0]);
- if (openvpn_swprintf(data, len, = default_value))
+ = if (swprintf(data, len, default_value))
{
status =3D ERROR_SUCCESS;
= }
@@ -93,7 +63,7 @@
TCHAR install_pat= h[MAX_PATH];
TCHAR default_value[MAX_PATH];
=
- openvpn_sw= printf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKAGE_NA= ME "%ls"), service_instance);
+ swprintf(reg_path, _countof(reg_path), TEXT("S= OFTWARE\\" PACKAGE_NAME "%ls"), service_instance);
LONG status =3D RegOpenKeyEx(HKEY_LOCAL_MACHI= NE, reg_path, 0, KEY_READ, &key);
if (status !=3D = ERROR_SUCCESS)
@@ -110,15 +80,15 @@
= goto out;
}

- openvpn_swprintf(default_value, _counto= f(default_value), TEXT("%ls\\bin\\openvpn.exe"),
- install_path);
+ swprintf(default_v= alue, _countof(default_value), TEXT("%ls\\bin\\openvpn.exe"),
+ install_pa= th);
error =3D GetRegString(key, TEXT("exe_path&q= uot;), s->exe_path, sizeof(s->exe_path), default_value);
if (error !=3D ERROR_SUCCESS)

{
goto out;

}

- openvpn_swprintf(default_value= , _countof(default_value), TEXT("%ls\\config"), install_path);
+ swprintf(default_v= alue, _countof(default_value), TEXT("%ls\\config"), install_path)= ;
error =3D GetRegString(key, TEXT("config_dir&qu= ot;), s->config_dir, sizeof(s->config_dir),
= default_value);
if (error !=3D ERROR_= SUCCESS)
@@ -133,7 +103,7 @@
goto = out;
}

- openvpn_swprintf(default_value, _countof(defaul= t_value), TEXT("%ls\\log"), install_path);
+ swprintf(default_value, _countof(defa= ult_value), TEXT("%ls\\log"), install_path);
= error =3D GetRegString(key, TEXT("log_dir"), s->log_dir, size= of(s->log_dir), default_value);
if (error !=3D ERRO= R_SUCCESS)
{
@@ -229,7 +199,7 @@
else
{
tmp[wc= slen(tmp) - 2] =3D TEXT('\0'); /* remove CR/LF characters */=
- openvpn_swprintf(buf= , _countof(buf), TEXT("%ls (0x%x)"), tmp, error);
+ swprintf(buf, _countof(buf)= , TEXT("%ls (0x%x)"), tmp, error);

}<= br>
if (tmp)
@@ -259,12 +229,12= @@
hEventSource =3D RegisterEventSource(NULL, APPNAME= );
if (hEventSource !=3D NULL)
{<= /span>
- openvpn_swprin= tf(msg[0], _countof(msg[0]),
- TEXT("%ls%ls%ls: %ls"), APPNAME, = service_instance,
- = (flags & MSG_FLAGS_ERROR) ? TEXT(" error"= ;) : TEXT(""), err_msg);
+ swprintf(msg[0], _countof(msg[0]),
+ TEXT("%ls%ls%ls= : %ls"), APPNAME, service_instance,
+ (flags & MSG_FLAGS_ERROR) ? TEXT(= " error") : TEXT(""), err_msg);

va_start(arglist, format);
- openvpn_vswprintf(msg[1], _countof(msg[1])= , format, arglist);
+= vswprintf(msg[1], _countof(msg[1]), format, arglist);
va_end(arglist);


con= st TCHAR *mesg[] =3D { msg[0], msg[1] };
diff --git a/src/o= penvpnserv/interactive.c b/src/openvpnserv/interactive.c
in= dex d32223c..ee56989 100644
--- a/src/openvpnserv/interacti= ve.c
+++ b/src/openvpnserv/interactive.c
@@= -311,7 +311,7 @@
* Same format as error messages (3 = line string) with error =3D 0 in
* 0x%08x format, PID= on line 2 and a description "Process ID" on line 3
*/

- openvp= n_swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, ms= g);
+ swprintf(buf= , _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, msg);
=
WritePipeAsync(pipe, buf, (DWORD)(wcslen(buf) = * 2), count, events);
}
@@ -385,9 +385,9 @= @

if (!argv)
{<= /span>
- openvpn_swprin= tf(errmsg, capacity,
- = L"Cannot validate options: CommandLineToArgvW = failed with error =3D 0x%08x",
- GetLastError());
+ swprintf(errmsg, capacity,
+ L"= Cannot validate options: CommandLineToArgvW failed with error =3D 0x%08x&qu= ot;,
+ = GetLastError());
goto out;
= }

@@ -407,8 +407,8 @@

if (!CheckOption(workdir, 2, argv_tmp, &setting= s))
{
- openvpn_swprintf(errmsg, capacity, msg1, argv[0], work= dir,
- = settings.ovpn_admin_group);
+ swprintf(errmsg, capacity, msg1, argv[0], w= orkdir,
+ = settings.ovpn_admin_group);
}
<= span> goto out;

}
@@ -424,13 += 424,13 @@
{
if (wcscm= p(L"--config", argv[i]) =3D=3D 0 && argc-i > 1)=
{
- = settings.ovpn_admin_group);
+ swprintf(errmsg, capacity, msg1, ar= gv[i+1], workdir,
+ = settings.ovpn_admin_group);
= }
else
{
- openvpn_s= wprintf(errmsg, capacity, msg2, argv[i],
- settings.ovpn_admin_gro= up);
+ = swprintf(errmsg, capacity, msg2, argv[i],
+ settings.ovpn_admin_group);=
}
goto out;
}
@@ -985,7 +985,7 @@
=
HANDLE wait_handles[2] =3D {rdns_semaphore, exit_eve= nt};

= - openvpn_swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_p= ath(), L"ipconfig.exe");
+ swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win= _sys_path(), L"ipconfig.exe");

= if (WaitForMultipleObjects(2, wait_handles, FALSE, timeout) =3D=3D WAI= T_OBJECT_0)
{
@@ -1064,7 +1064,7 @@
}

/* Path of nets= h */
- openvpn_swpri= ntf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L&qu= ot;netsh.exe");
= + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_pa= th(), L"netsh.exe");

/* cm= d template:
* netsh interface $proto $action dns $if_= name $addr [validate=3Dno]
@@ -1080,7 +1080,7 @@
= goto out;
}
- openvpn_swprintf(cmdline, n= cmdline, fmt, proto, action, if_name, addr);
+ swprintf(cmdline, ncmdline, fmt, proto, action= , if_name, addr);

if (IsWindows7OrGr= eater())
{
@@ -1124,7 +1124,7 @@
}

/* Path of netsh *= /
- openvpn_swprintf= (argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"= netsh.exe");
+ = swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(= ), L"netsh.exe");

/* cmd t= emplate:
* netsh interface ip $action wins $if_name $= static $addr
@@ -1141,7 +1141,7 @@
= goto out;
}

- openvpn_swprintf(cmdline, ncmdline, fmt= , action, if_name, addr_static, addr);
+ swprintf(cmdline, ncmdline, fmt, action, if_name, ad= dr_static, addr);

err =3D ExecComman= d(argv0, cmdline, timeout);

@@ -1167,7 +1= 167,7 @@
wchar_t *cmdline =3D NULL;
= int timeout =3D 10000; /* in msec */

- openvpn_swprintf(argv0, _countof(ar= gv0), L"%ls\\%ls", get_win_sys_path(), L"wbem\\wmic.exe"= ;);
+ swprintf(arg= v0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"wbem= \\wmic.exe");

const wchar_t *fm= t;
/* comma separated list must be enclosed in parenth= esis */
@@ -1188,8 +1188,8 @@
retu= rn ERROR_OUTOFMEMORY;
}

- openvpn_swprintf(cmdline, ncmd= line, fmt, if_index, action,

- data ? data : L"");
+ swprintf(cmdline, ncmdline, fmt, = if_index, action,
+ = data ? data : L"");
err =3D ExecC= ommand(argv0, cmdline, timeout);

fre= e(cmdline);
@@ -1453,7 +1453,7 @@
wcha= r_t argv0[MAX_PATH];

/* Path of nets= h */
- openvpn_swpri= ntf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L&qu= ot;netsh.exe");
= + swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_pa= th(), L"netsh.exe");

/* cm= d template:
* netsh interface ipv4 set address name= =3D$if_index source=3Ddhcp
@@ -1471,7 +1471,7 @@
= return err;
}
<= br>- openvpn_swprintf(cmdline,= ncmdline, fmt, dhcp->iface.index);
+ swprintf(cmdline, ncmdline, fmt, dhcp->iface.inde= x);

err =3D ExecCommand(argv0, cmdli= ne, timeout);

@@ -1970,8 +1970,8 @@
goto out;
}

- openvpn_swprintf(ovpn_= pipe_name, _countof(ovpn_pipe_name),
- TEXT("\\\\.\\pipe\\" PACKAGE = "%ls\\service_%lu"), service_instance, GetCurrentThreadId());
+ swprintf(ovpn_pipe_= name, _countof(ovpn_pipe_name),
+ TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\= service_%lu"), service_instance, GetCurrentThreadId());
ovpn_pipe =3D CreateNamedPipe(ovpn_pipe_name,

= PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTAN= CE | FILE_FLAG_OVERLAPPED,
= PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 128, 128, 0, NUL= L);
@@ -2003,8 +2003,8 @@
ReturnLa= stError(pipe, L"malloc");
goto out;
}
- = openvpn_swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %= " PRIuPTR,
- = sud.options, svc_pipe);
+ swprintf(cmdline, cmdline_size, L"openvpn %ls -= -msg-channel %" PRIuPTR,
+ sud.options, svc_pipe);

= if (!CreateEnvironmentBlock(&user_env, imp_token, FALSE))
{
@@ -2079,8 +2079,8 @@
= else if (exit_code !=3D 0)
{
= WCHAR buf[256];
- = openvpn_swprintf(buf, _countof(buf),
- L"OpenVPN exited with e= rror: exit code =3D %lu", exit_code);
+ swprintf(buf, _countof(buf),
+ L"OpenVPN exi= ted with error: exit code =3D %lu", exit_code);

= ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event);
}
Undo(&undo_lists);
@@ -2174,7 +2174,7 @@

initialized =3D TRUE;
}

- openvpn_swprintf(pipe_name, _countof(pipe_name), TEXT(&= quot;\\\\.\\pipe\\" PACKAGE "%ls\\service"), service_instanc= e);
+ swprintf(pip= e_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\" PACKAGE "%= ls\\service"), service_instance);
pipe =3D Create= NamedPipe(pipe_name, flags,
PIP= E_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS,=
PIPE_UNLIMITED_INSTANCES, 1024, 1024,= 0, NULL);
diff --git a/src/openvpnserv/service.h b/src/ope= nvpnserv/service.h
index 3acf08c..6d0827d 100644
= --- a/src/openvpnserv/service.h
+++ b/src/openvpnserv= /service.h
@@ -81,12 +81,6 @@

<= span> VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
=

-BOOL openv= pn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
-
-BOOL openvpn_sntprintf(LPTSTR str, size_t s= ize, LPCTSTR format, ...);
-
-BOOL openvpn_swp= rintf(wchar_t *const str, const size_t size, const wchar_t *const format, .= ..);
-
= DWORD GetOpenvpnSettings(settings_t *s);

BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *s= tatus);

diff --git a/src/openvpnserv/validate.c b/src/openv= pnserv/validate.c
index 5f7acd7..9563fa5 100644
<= span>--- a/src/openvpnserv/validate.c

+++ b/src/openvpnserv= /validate.c
@@ -68,7 +68,7 @@
/* conve= rt fname to full path */
if (PathIsRelativeW(fname) )<= /span>
{
= - openvpn_swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdi= r, fname);
+ s= wprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname);<= br> config_file =3D tmp;
}
else

diff --git a/tests/unit_tests/openvpn/test_buf= fer.c b/tests/unit_tests/openvpn/test_buffer.c
index 52ffb5= 4..9a61f2f 100644
--- a/tests/unit_tests/openvpn/test_buffe= r.c
+++ b/tests/unit_tests/openvpn/test_buffer.c
= @@ -354,6 +354,56 @@
assert_string_equal(buf, &q= uot;There is a .'nice.' \"1234\" [.] year old .tree!"= ;);
}

+static void
+test_snprintf(void **state)
+{
+ * OS (the commen= t did not specify which) did not always put the
+ * null byte there. So we unit test this to= be sure.
+ *
+ * This probably re= fers to the MSVC behaviour, see also
+ * https://stackoverflow.com/questions/7706936/is-snpr= intf-always-null-terminating
+ */
+
+ /* Instead of tryi= ng to trick the compiler here, disable the warnings
+ * for this unit test. We know that a= re doing this that are truncated
+ * and we want to test that */
+#if defined(__GNUC__)
+/* some clang version do not understand -Wfor= mat-truncation, so ignore the
+ * warning to avoid warnings/errors (-Werror) about unknown pragm= a/option */
+#if defi= ned(__clang__)
+#prag= ma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunknown-warning-option"<= /span>
+#endif
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ig= nored "-Wformat-truncation"
+#endif
+
+ char buf[1= 0] =3D { 'a' };
+ int ret =3D 0;
+ ret =3D snpr= intf(buf, sizeof(buf), "0123456789abcde");
+ assert_int_equal(ret, 15);
= + assert_int_equal(buf[9], &= #39;\0');
+
+ memset(buf, 'b= 9;, sizeof(buf));
+ = ret =3D snprintf(buf, sizeof(buf), "- %d - %d -", 77, 88);
+ assert_int_equal(ret= , 11);
+ assert_in= t_equal(buf[9], '\0');
+
+ mems= et(buf, 'c', sizeof(buf));
+ ret =3D snprintf(buf, sizeof(buf), "- %8.2f", = 77.8899);
+ assert= _int_equal(ret, 10);
= + assert_int_equal(buf[9], '\0');
+
+#if defined(__GNUC__)
+#if defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+#pragma GCC diagnostic pop
+#endif
+}=
+
i= nt
main(void)
{
@@ -387,6= +437,7 @@
cmocka_unit_test(test_buffer_free_gc_tw= o),
cmocka_unit_test(test_buffer_gc_realloc),
cmocka_unit_test(test_character_class),
+ cmocka_unit_test(test_snpr= intf)

};

return= cmocka_run_group_tests_name("buffer", tests, NULL, NULL);=
diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/un= it_tests/openvpn/test_cryptoapi.c
index 87f6208..98102ef 10= 0644
--- a/tests/unit_tests/openvpn/test_cryptoapi.c=
+++ b/tests/unit_tests/openvpn/test_cryptoapi.c
@= @ -271,7 +271,7 @@

for (struct test_= cert *c =3D certs; c->cert; c++)
{
- openvpn_snprintf(select_string= , sizeof(select_string), "THUMB:%s", c->hash);
+ snprintf(select_string, siz= eof(select_string), "THUMB:%s", c->hash);

= ctx =3D find_certificate_in_store(select_string, user_store); if (ctx)
{
@@ -30= 4,7 +304,7 @@

for (struct test_cert = *c =3D certs; c->cert; c++)
{
- openvpn_snprintf(select_string, siz= eof(select_string), "SUBJ:%s", c->cname);
+ snprintf(select_string, sizeof(s= elect_string), "SUBJ:%s", c->cname);
= ctx =3D find_certificate_in_store(select_string, user_store);
/* In this case we expect a successful return as there is at le= ast one valid

* cert that matches the common name= . But the returned cert may not exactly match
@@ -337,7 +33= 7,7 @@

for (struct test_cert *c =3D = certs; c->cert; c++)
{
- openvpn_snprintf(select_string, sizeof(sel= ect_string), "ISSUER:%s", c->issuer);
+ snprintf(select_string, sizeof(selec= t_string), "ISSUER:%s", c->issuer);
c= tx =3D find_certificate_in_store(select_string, user_store);
/* In this case we expect a successful return as there is at lea= st one valid

* cert that matches the issuer. But = the returned cert may not exactly match
@@ -411,7 +411,7 @@=
{
continue; }
- = openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s&= quot;, c->hash);
+= snprintf(select_string, sizeof(select_string), "THUMB:%s"= , c->hash);
if (Load_CryptoAPI_certificate(sele= ct_string, &x509, &privkey) !=3D 1)
{
fail_msg("Load_CryptoAPI_certificate failed: = <%s>", c->friendly_name);
@@ -446,7 +446,7 @@=
SSL_CTX *ssl_ctx =3D SSL_CTX_new_ex(tls_libctx, N= ULL, SSLv23_client_method());
assert_non_null(ssl_= ctx);

- openvpn_snprintf(select_string, sizeof(select_string), "THUM= B:%s", c->hash);
+ snprintf(select_string, sizeof(select_string), "THUMB:%s&= quot;, c->hash);
if (!SSL_CTX_use_CryptoAPI_cer= tificate(ssl_ctx, select_string))
{
fail_msg("SSL_CTX_use_CryptoAPI_certificate failed: <= ;%s>", c->friendly_name);

diff --git a/tests/uni= t_tests/openvpn/test_pkcs11.c b/tests/unit_tests/openvpn/test_pkcs11.c
index a48e404..84ebb29 100644
--- a/tests/unit_= tests/openvpn/test_pkcs11.c
+++ b/tests/unit_tests/openvpn/= test_pkcs11.c
@@ -161,7 +161,7 @@
}
else if (flags & GET_USER_PASS_PASSWORD_ONLY)=
{
- = openvpn_snprintf(up->password, sizeof(up->password), "%s"= ;, PIN);
+ snp= rintf(up->password, sizeof(up->password), "%s", PIN);
}
else
{@@ -204,8 +204,8 @@
{
= fail_msg("make tmpfile using template <%s> failed (error =3D %d= )", softhsm2_conf_path, errno);
}
- openvpn_snprintf(config, sizeof(c= onfig), "directories.tokendir=3D%s/",

- softhsm2_tokens_path);
+ snprintf(config, size= of(config), "directories.tokendir=3D%s/",
+ softhsm2_tokens_path);
assert_int_equal(write(fd, config, strlen(config)), strlen(= config));
close(fd);


To view, visit change 547. To unsubscribe, or for help writ= ing mail filters, visit sett= ings.

<= link itemprop=3D"url" href=3D"http://gerrit.openvpn.net/c/openvpn/+/547?usp= =3Demail"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07096977e3b562bcb5d2c6f1167= 3a4175b8e12ac
Gerrit-Change-Number: 547
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: ordex <a@...2181...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: ordex <a@...2181...> <= /div>
Gerrit-MessageType: newpatchset
--LLwum9NYQ7I=--