Browse code

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-terminating
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 <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20240506102710.8976-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28617.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Arne Schwabe authored on 2024/05/06 19:27:10
Showing 38 changed files
... ...
@@ -279,32 +279,6 @@ buf_puts(struct buffer *buf, const char *str)
279 279
     return ret;
280 280
 }
281 281
 
282
-
283
-/*
284
- * This is necessary due to certain buggy implementations of snprintf,
285
- * that don't guarantee null termination for size > 0.
286
- *
287
- * Return false on overflow.
288
- *
289
- * This functionality is duplicated in src/openvpnserv/common.c
290
- * Any modifications here should be done to the other place as well.
291
- */
292
-
293
-bool
294
-openvpn_snprintf(char *str, size_t size, const char *format, ...)
295
-{
296
-    va_list arglist;
297
-    int len = -1;
298
-    if (size > 0)
299
-    {
300
-        va_start(arglist, format);
301
-        len = vsnprintf(str, size, format, arglist);
302
-        va_end(arglist);
303
-        str[size - 1] = 0;
304
-    }
305
-    return (len >= 0 && len < size);
306
-}
307
-
308 282
 /*
309 283
  * write a string to the end of a buffer that was
310 284
  * truncated by buf_printf
... ...
@@ -448,19 +448,6 @@ __attribute__ ((format(__printf__, 2, 3)))
448 448
  */
449 449
 bool buf_puts(struct buffer *buf, const char *str);
450 450
 
451
-/*
452
- * Like snprintf but guarantees null termination for size > 0
453
- */
454
-bool openvpn_snprintf(char *str, size_t size, const char *format, ...)
455
-#ifdef __GNUC__
456
-#if __USE_MINGW_ANSI_STDIO
457
-__attribute__ ((format(gnu_printf, 3, 4)))
458
-#else
459
-__attribute__ ((format(__printf__, 3, 4)))
460
-#endif
461
-#endif
462
-;
463
-
464 451
 
465 452
 /*
466 453
  * remove/add trailing characters
... ...
@@ -874,11 +874,11 @@ init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2,
874 874
 
875 875
     key_direction_state_init(&kds, key_direction);
876 876
 
877
-    openvpn_snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name);
877
+    snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name);
878 878
     init_key_ctx(&ctx->encrypt, &key2->keys[kds.out_key], kt,
879 879
                  OPENVPN_OP_ENCRYPT, log_prefix);
880 880
 
881
-    openvpn_snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name);
881
+    snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name);
882 882
     init_key_ctx(&ctx->decrypt, &key2->keys[kds.in_key], kt,
883 883
                  OPENVPN_OP_DECRYPT, log_prefix);
884 884
 
... ...
@@ -128,7 +128,7 @@ mbed_log_func_line(unsigned int flags, int errval, const char *func,
128 128
 {
129 129
     char prefix[256];
130 130
 
131
-    if (!openvpn_snprintf(prefix, sizeof(prefix), "%s:%d", func, line))
131
+    if (!snprintf(prefix, sizeof(prefix), "%s:%d", func, line))
132 132
     {
133 133
         return mbed_log_err(flags, errval, func);
134 134
     }
... ...
@@ -239,11 +239,11 @@ crypto_pem_encode(const char *name, struct buffer *dst,
239 239
     char header[1000+1] = { 0 };
240 240
     char footer[1000+1] = { 0 };
241 241
 
242
-    if (!openvpn_snprintf(header, sizeof(header), "-----BEGIN %s-----\n", name))
242
+    if (!snprintf(header, sizeof(header), "-----BEGIN %s-----\n", name))
243 243
     {
244 244
         return false;
245 245
     }
246
-    if (!openvpn_snprintf(footer, sizeof(footer), "-----END %s-----\n", name))
246
+    if (!snprintf(footer, sizeof(footer), "-----END %s-----\n", name))
247 247
     {
248 248
         return false;
249 249
     }
... ...
@@ -278,11 +278,11 @@ crypto_pem_decode(const char *name, struct buffer *dst,
278 278
     char header[1000+1] = { 0 };
279 279
     char footer[1000+1] = { 0 };
280 280
 
281
-    if (!openvpn_snprintf(header, sizeof(header), "-----BEGIN %s-----", name))
281
+    if (!snprintf(header, sizeof(header), "-----BEGIN %s-----", name))
282 282
     {
283 283
         return false;
284 284
     }
285
-    if (!openvpn_snprintf(footer, sizeof(footer), "-----END %s-----", name))
285
+    if (!snprintf(footer, sizeof(footer), "-----END %s-----", name))
286 286
     {
287 287
         return false;
288 288
     }
... ...
@@ -349,11 +349,11 @@ setenv_dns_option(struct env_set *es,
349 349
 
350 350
     if (j < 0)
351 351
     {
352
-        name_ok = openvpn_snprintf(name, sizeof(name), format, i);
352
+        name_ok = snprintf(name, sizeof(name), format, i);
353 353
     }
354 354
     else
355 355
     {
356
-        name_ok = openvpn_snprintf(name, sizeof(name), format, i, j);
356
+        name_ok = snprintf(name, sizeof(name), format, i, j);
357 357
     }
358 358
 
359 359
     if (!name_ok)
... ...
@@ -259,7 +259,7 @@ void
259 259
 setenv_counter(struct env_set *es, const char *name, counter_type value)
260 260
 {
261 261
     char buf[64];
262
-    openvpn_snprintf(buf, sizeof(buf), counter_format, value);
262
+    snprintf(buf, sizeof(buf), counter_format, value);
263 263
     setenv_str(es, name, buf);
264 264
 }
265 265
 
... ...
@@ -267,7 +267,7 @@ void
267 267
 setenv_int(struct env_set *es, const char *name, int value)
268 268
 {
269 269
     char buf[64];
270
-    openvpn_snprintf(buf, sizeof(buf), "%d", value);
270
+    snprintf(buf, sizeof(buf), "%d", value);
271 271
     setenv_str(es, name, buf);
272 272
 }
273 273
 
... ...
@@ -275,7 +275,7 @@ void
275 275
 setenv_long_long(struct env_set *es, const char *name, long long value)
276 276
 {
277 277
     char buf[64];
278
-    openvpn_snprintf(buf, sizeof(buf), "%" PRIi64, (int64_t)value);
278
+    snprintf(buf, sizeof(buf), "%" PRIi64, (int64_t)value);
279 279
     setenv_str(es, name, buf);
280 280
 }
281 281
 
... ...
@@ -310,7 +310,7 @@ setenv_str_incr(struct env_set *es, const char *name, const char *value)
310 310
     strcpy(tmpname, name);
311 311
     while (NULL != env_set_get(es, tmpname) && counter < 1000)
312 312
     {
313
-        ASSERT(openvpn_snprintf(tmpname, tmpname_len, "%s_%u", name, counter));
313
+        ASSERT(snprintf(tmpname, tmpname_len, "%s_%u", name, counter));
314 314
         counter++;
315 315
     }
316 316
     if (counter < 1000)
... ...
@@ -274,14 +274,14 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
274 274
 
275 275
     if ((flags & M_ERRNO) && e)
276 276
     {
277
-        openvpn_snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=%d)",
278
-                         m1, openvpn_strerror(e, crt_error, &gc), e);
277
+        snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=%d)",
278
+                 m1, openvpn_strerror(e, crt_error, &gc), e);
279 279
         SWAP;
280 280
     }
281 281
 
282 282
     if (flags & M_OPTERR)
283 283
     {
284
-        openvpn_snprintf(m2, ERR_BUF_SIZE, "Options error: %s", m1);
284
+        snprintf(m2, ERR_BUF_SIZE, "Options error: %s", m1);
285 285
         SWAP;
286 286
     }
287 287
 
... ...
@@ -321,10 +321,10 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
321 321
         const struct virtual_output *vo = msg_get_virtual_output();
322 322
         if (vo)
323 323
         {
324
-            openvpn_snprintf(m2, ERR_BUF_SIZE, "%s%s%s",
325
-                             prefix,
326
-                             prefix_sep,
327
-                             m1);
324
+            snprintf(m2, ERR_BUF_SIZE, "%s%s%s",
325
+                     prefix,
326
+                     prefix_sep,
327
+                     m1);
328 328
             virtual_output_print(vo, flags, m2);
329 329
         }
330 330
     }
... ...
@@ -359,7 +359,7 @@ management_callback_remote_entry_get(void *arg, unsigned int index, char **remot
359 359
         char *out = malloc(len);
360 360
         check_malloc_return(out);
361 361
 
362
-        openvpn_snprintf(out, len, "%s,%s,%s,%s", ce->remote, ce->remote_port, proto, status);
362
+        snprintf(out, len, "%s,%s,%s,%s", ce->remote, ce->remote_port, proto, status);
363 363
         *remote = out;
364 364
     }
365 365
     else
... ...
@@ -515,8 +515,8 @@ man_bytecount_output_client(struct management *man,
515 515
     char out[32];
516 516
 
517 517
     /* do in a roundabout way to work around possible mingw or mingw-glibc bug */
518
-    openvpn_snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + dco_read_bytes);
519
-    openvpn_snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + dco_write_bytes);
518
+    snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + dco_read_bytes);
519
+    snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + dco_write_bytes);
520 520
     msg(M_CLIENT, ">BYTECOUNT:%s,%s", in, out);
521 521
 }
522 522
 
... ...
@@ -528,8 +528,8 @@ man_bytecount_output_server(const counter_type *bytes_in_total,
528 528
     char in[32];
529 529
     char out[32];
530 530
     /* do in a roundabout way to work around possible mingw or mingw-glibc bug */
531
-    openvpn_snprintf(in, sizeof(in), counter_format, *bytes_in_total);
532
-    openvpn_snprintf(out, sizeof(out), counter_format, *bytes_out_total);
531
+    snprintf(in, sizeof(in), counter_format, *bytes_in_total);
532
+    snprintf(out, sizeof(out), counter_format, *bytes_out_total);
533 533
     msg(M_CLIENT, ">BYTECOUNT_CLI:%lu,%s,%s", mdac->cid, in, out);
534 534
     mdac->bytecount_last_update = now;
535 535
 }
... ...
@@ -1427,7 +1427,7 @@ foreign_options_copy_dns(struct options *o, struct env_set *es)
1427 1427
     for (int i = 1; i <= opt_max; ++i)
1428 1428
     {
1429 1429
         char name[32];
1430
-        openvpn_snprintf(name, sizeof(name), "foreign_option_%d", i);
1430
+        snprintf(name, sizeof(name), "foreign_option_%d", i);
1431 1431
 
1432 1432
         const char *env_str = env_set_get(es, name);
1433 1433
         const char *value = strchr(env_str, '=') + 1;
... ...
@@ -1482,7 +1482,7 @@ foreign_options_copy_dns(struct options *o, struct env_set *es)
1482 1482
     while (o->foreign_option_index < opt_max)
1483 1483
     {
1484 1484
         char name[32];
1485
-        openvpn_snprintf(name, sizeof(name), "foreign_option_%d", opt_max--);
1485
+        snprintf(name, sizeof(name), "foreign_option_%d", opt_max--);
1486 1486
         setenv_del(es, name);
1487 1487
     }
1488 1488
 }
... ...
@@ -5674,8 +5674,8 @@ set_user_script(struct options *options,
5674 5674
 #ifndef ENABLE_SMALL
5675 5675
     {
5676 5676
         char script_name[100];
5677
-        openvpn_snprintf(script_name, sizeof(script_name),
5678
-                         "--%s script", type);
5677
+        snprintf(script_name, sizeof(script_name),
5678
+                 "--%s script", type);
5679 5679
 
5680 5680
         if (check_cmd_access(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
5681 5681
         {
... ...
@@ -201,7 +201,7 @@ _pkcs11_openvpn_token_prompt(
201 201
     CLEAR(token_resp);
202 202
     token_resp.defined = false;
203 203
     token_resp.nocache = true;
204
-    openvpn_snprintf(
204
+    snprintf(
205 205
         token_resp.username,
206 206
         sizeof(token_resp.username),
207 207
         "Please insert %s token",
... ...
@@ -245,7 +245,7 @@ _pkcs11_openvpn_pin_prompt(
245 245
 
246 246
     ASSERT(token!=NULL);
247 247
 
248
-    openvpn_snprintf(prompt, sizeof(prompt), "%s token", token->label);
248
+    snprintf(prompt, sizeof(prompt), "%s token", token->label);
249 249
 
250 250
     token_pass.defined = false;
251 251
     token_pass.nocache = true;
... ...
@@ -719,7 +719,7 @@ tls_ctx_use_pkcs11(
719 719
 
720 720
         id_resp.defined = false;
721 721
         id_resp.nocache = true;
722
-        openvpn_snprintf(
722
+        snprintf(
723 723
             id_resp.username,
724 724
             sizeof(id_resp.username),
725 725
             "Please specify PKCS#11 id to use"
... ...
@@ -564,9 +564,9 @@ platform_create_temp_file(const char *directory, const char *prefix, struct gc_a
564 564
     {
565 565
         ++attempts;
566 566
 
567
-        if (!openvpn_snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len,
568
-                              prefix, (unsigned long) get_random(),
569
-                              (unsigned long) get_random()))
567
+        if (!snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len,
568
+                      prefix, (unsigned long) get_random(),
569
+                      (unsigned long) get_random()))
570 570
         {
571 571
             msg(M_WARN, "ERROR: temporary filename too long");
572 572
             return NULL;
... ...
@@ -260,7 +260,7 @@ plugin_init_item(struct plugin *p, const struct plugin_option *o)
260 260
     {
261 261
         char full[PATH_MAX];
262 262
 
263
-        openvpn_snprintf(full, sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so_pathname);
263
+        snprintf(full, sizeof(full), "%s/%s", PLUGIN_LIBDIR, p->so_pathname);
264 264
         p->handle = dlopen(full, RTLD_NOW);
265 265
     }
266 266
     else
... ...
@@ -409,7 +409,7 @@ plugin_vlog(openvpn_plugin_log_flags_t flags, const char *name, const char *form
409 409
 
410 410
         gc_init(&gc);
411 411
         msg_fmt = gc_malloc(ERR_BUF_SIZE, false, &gc);
412
-        openvpn_snprintf(msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, format);
412
+        snprintf(msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, format);
413 413
         x_msg_va(msg_flags, msg_fmt, arglist);
414 414
 
415 415
         gc_free(&gc);
... ...
@@ -766,7 +766,7 @@ ifconfig_pool_test(in_addr_t start, in_addr_t end)
766 766
         ifconfig_pool_handle h;
767 767
         in_addr_t local, remote;
768 768
         char buf[256];
769
-        openvpn_snprintf(buf, sizeof(buf), "common-name-%d", i);
769
+        snprintf(buf, sizeof(buf), "common-name-%d", i);
770 770
 #ifdef DUP_CN
771 771
         cn = NULL;
772 772
 #else
... ...
@@ -582,9 +582,9 @@ add_proxy_headers(struct http_proxy_info *p,
582 582
     {
583 583
         if (p->options.custom_headers[i].content)
584 584
         {
585
-            openvpn_snprintf(buf, sizeof(buf), "%s: %s",
586
-                             p->options.custom_headers[i].name,
587
-                             p->options.custom_headers[i].content);
585
+            snprintf(buf, sizeof(buf), "%s: %s",
586
+                     p->options.custom_headers[i].name,
587
+                     p->options.custom_headers[i].content);
588 588
             if (!strcasecmp(p->options.custom_headers[i].name, "Host"))
589 589
             {
590 590
                 host_header_sent = true;
... ...
@@ -592,8 +592,8 @@ add_proxy_headers(struct http_proxy_info *p,
592 592
         }
593 593
         else
594 594
         {
595
-            openvpn_snprintf(buf, sizeof(buf), "%s",
596
-                             p->options.custom_headers[i].name);
595
+            snprintf(buf, sizeof(buf), "%s",
596
+                     p->options.custom_headers[i].name);
597 597
             if (!strncasecmp(p->options.custom_headers[i].name, "Host:", 5))
598 598
             {
599 599
                 host_header_sent = true;
... ...
@@ -609,7 +609,7 @@ add_proxy_headers(struct http_proxy_info *p,
609 609
 
610 610
     if (!host_header_sent)
611 611
     {
612
-        openvpn_snprintf(buf, sizeof(buf), "Host: %s", host);
612
+        snprintf(buf, sizeof(buf), "Host: %s", host);
613 613
         msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
614 614
         if (!send_line_crlf(sd, buf))
615 615
         {
... ...
@@ -620,8 +620,8 @@ add_proxy_headers(struct http_proxy_info *p,
620 620
     /* send User-Agent string if provided */
621 621
     if (p->options.user_agent)
622 622
     {
623
-        openvpn_snprintf(buf, sizeof(buf), "User-Agent: %s",
624
-                         p->options.user_agent);
623
+        snprintf(buf, sizeof(buf), "User-Agent: %s",
624
+                 p->options.user_agent);
625 625
         msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
626 626
         if (!send_line_crlf(sd, buf))
627 627
         {
... ...
@@ -667,10 +667,10 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
667 667
     else
668 668
     {
669 669
         /* format HTTP CONNECT message */
670
-        openvpn_snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
671
-                         host,
672
-                         port,
673
-                         p->options.http_version);
670
+        snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
671
+                 host,
672
+                 port,
673
+                 p->options.http_version);
674 674
 
675 675
         msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
676 676
 
... ...
@@ -692,8 +692,8 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
692 692
                 break;
693 693
 
694 694
             case HTTP_AUTH_BASIC:
695
-                openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: Basic %s",
696
-                                 username_password_as_base64(p, &gc));
695
+                snprintf(buf, sizeof(buf), "Proxy-Authorization: Basic %s",
696
+                         username_password_as_base64(p, &gc));
697 697
                 msg(D_PROXY, "Attempting Basic Proxy-Authorization");
698 698
                 dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf);
699 699
                 if (!send_line_crlf(sd, buf))
... ...
@@ -705,14 +705,14 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
705 705
 #if NTLM
706 706
             case HTTP_AUTH_NTLM2:
707 707
                 /* keep-alive connection */
708
-                openvpn_snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
708
+                snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
709 709
                 if (!send_line_crlf(sd, buf))
710 710
                 {
711 711
                     goto error;
712 712
                 }
713 713
 
714
-                openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",
715
-                                 ntlm_phase_1(p, &gc));
714
+                snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",
715
+                         ntlm_phase_1(p, &gc));
716 716
                 msg(D_PROXY, "Attempting NTLM Proxy-Authorization phase 1");
717 717
                 dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf);
718 718
                 if (!send_line_crlf(sd, buf))
... ...
@@ -773,7 +773,7 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
773 773
 
774 774
                 char get[80];
775 775
                 CLEAR(buf2);
776
-                openvpn_snprintf(get, sizeof(get), "%%*s NTLM %%%zus", sizeof(buf2) - 1);
776
+                snprintf(get, sizeof(get), "%%*s NTLM %%%zus", sizeof(buf2) - 1);
777 777
                 nparms = sscanf(buf, get, buf2);
778 778
 
779 779
                 /* check for "Proxy-Authenticate: NTLM TlRM..." */
... ...
@@ -795,10 +795,10 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
795 795
             /* now send the phase 3 reply */
796 796
 
797 797
             /* format HTTP CONNECT message */
798
-            openvpn_snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
799
-                             host,
800
-                             port,
801
-                             p->options.http_version);
798
+            snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
799
+                     host,
800
+                     port,
801
+                     p->options.http_version);
802 802
 
803 803
             msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
804 804
 
... ...
@@ -809,7 +809,7 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
809 809
             }
810 810
 
811 811
             /* keep-alive connection */
812
-            openvpn_snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
812
+            snprintf(buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
813 813
             if (!send_line_crlf(sd, buf))
814 814
             {
815 815
                 goto error;
... ...
@@ -829,7 +829,7 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
829 829
                     msg(D_PROXY, "NTLM Proxy-Authorization phase 3 failed: received corrupted data from proxy server");
830 830
                     goto error;
831 831
                 }
832
-                openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s", np3);
832
+                snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s", np3);
833 833
             }
834 834
 
835 835
             msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
... ...
@@ -899,15 +899,15 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
899 899
 
900 900
 
901 901
                 /* build the digest response */
902
-                openvpn_snprintf(uri, sizeof(uri), "%s:%s",
903
-                                 host,
904
-                                 port);
902
+                snprintf(uri, sizeof(uri), "%s:%s",
903
+                         host,
904
+                         port);
905 905
 
906 906
                 if (opaque)
907 907
                 {
908 908
                     const int len = strlen(opaque)+16;
909 909
                     opaque_kv = gc_malloc(len, false, &gc);
910
-                    openvpn_snprintf(opaque_kv, len, ", opaque=\"%s\"", opaque);
910
+                    snprintf(opaque_kv, len, ", opaque=\"%s\"", opaque);
911 911
                 }
912 912
 
913 913
                 DigestCalcHA1(algor,
... ...
@@ -928,10 +928,10 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
928 928
                                    response);
929 929
 
930 930
                 /* format HTTP CONNECT message */
931
-                openvpn_snprintf(buf, sizeof(buf), "%s %s HTTP/%s",
932
-                                 http_method,
933
-                                 uri,
934
-                                 p->options.http_version);
931
+                snprintf(buf, sizeof(buf), "%s %s HTTP/%s",
932
+                         http_method,
933
+                         uri,
934
+                         p->options.http_version);
935 935
 
936 936
                 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
937 937
 
... ...
@@ -948,21 +948,22 @@ establish_http_proxy_passthru(struct http_proxy_info *p,
948 948
                 }
949 949
 
950 950
                 /* send digest response */
951
-                int sret = openvpn_snprintf(buf, sizeof(buf), "Proxy-Authorization: Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", qop=%s, nc=%s, cnonce=\"%s\", response=\"%s\"%s",
952
-                                            username,
953
-                                            realm,
954
-                                            nonce,
955
-                                            uri,
956
-                                            qop,
957
-                                            nonce_count,
958
-                                            cnonce,
959
-                                            response,
960
-                                            opaque_kv
961
-                                            );
951
+                int sret = snprintf(buf, sizeof(buf), "Proxy-Authorization: Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", qop=%s, nc=%s, cnonce=\"%s\", response=\"%s\"%s",
952
+                                    username,
953
+                                    realm,
954
+                                    nonce,
955
+                                    uri,
956
+                                    qop,
957
+                                    nonce_count,
958
+                                    cnonce,
959
+                                    response,
960
+                                    opaque_kv
961
+                                    );
962 962
                 if (sret >= sizeof(buf))
963 963
                 {
964 964
                     goto error;
965 965
                 }
966
+
966 967
                 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
967 968
                 if (!send_line_crlf(sd, buf))
968 969
                 {
... ...
@@ -354,7 +354,7 @@ journal_add(const char *journal_dir, struct proxy_connection *pc, struct proxy_c
354 354
         fnlen =  strlen(journal_dir) + strlen(t) + 2;
355 355
         jfn = (char *) malloc(fnlen);
356 356
         check_malloc_return(jfn);
357
-        openvpn_snprintf(jfn, fnlen, "%s/%s", journal_dir, t);
357
+        snprintf(jfn, fnlen, "%s/%s", journal_dir, t);
358 358
         dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin %s -> %s", jfn, f);
359 359
         fd = platform_open(jfn, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
360 360
         if (fd != -1)
... ...
@@ -1621,11 +1621,11 @@ add_route(struct route_ipv4 *r,
1621 1621
 
1622 1622
     if (rgi)
1623 1623
     {
1624
-        openvpn_snprintf(out, sizeof(out), "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1624
+        snprintf(out, sizeof(out), "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1625 1625
     }
1626 1626
     else
1627 1627
     {
1628
-        openvpn_snprintf(out, sizeof(out), "%s %s %s", network, netmask, gateway);
1628
+        snprintf(out, sizeof(out), "%s %s %s", network, netmask, gateway);
1629 1629
     }
1630 1630
     bool ret = management_android_control(management, "ROUTE", out);
1631 1631
     status = ret ? RTA_SUCCESS : RTA_ERROR;
... ...
@@ -2000,7 +2000,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,
2000 2000
 #elif defined (TARGET_ANDROID)
2001 2001
     char out[64];
2002 2002
 
2003
-    openvpn_snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device);
2003
+    snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device);
2004 2004
 
2005 2005
     status = management_android_control(management, "ROUTE6", out);
2006 2006
 
... ...
@@ -66,8 +66,8 @@ openvpn_run_script(const struct argv *a, const struct env_set *es,
66 66
 {
67 67
     char msg[256];
68 68
 
69
-    openvpn_snprintf(msg, sizeof(msg),
70
-                     "WARNING: Failed running command (%s)", hook);
69
+    snprintf(msg, sizeof(msg),
70
+             "WARNING: Failed running command (%s)", hook);
71 71
     return openvpn_execve_check(a, es, flags | S_SCRIPT, msg);
72 72
 }
73 73
 
... ...
@@ -2983,11 +2983,11 @@ setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvp
2983 2983
         case AF_INET:
2984 2984
             if (flags & SA_IP_PORT)
2985 2985
             {
2986
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);
2986
+                snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);
2987 2987
             }
2988 2988
             else
2989 2989
             {
2990
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s", name_prefix);
2990
+                snprintf(name_buf, sizeof(name_buf), "%s", name_prefix);
2991 2991
             }
2992 2992
 
2993 2993
             inet_ntop(AF_INET, &addr->addr.in4.sin_addr, buf, sizeof(buf));
... ...
@@ -2995,7 +2995,7 @@ setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvp
2995 2995
 
2996 2996
             if ((flags & SA_IP_PORT) && addr->addr.in4.sin_port)
2997 2997
             {
2998
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefix);
2998
+                snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefix);
2999 2999
                 setenv_int(es, name_buf, ntohs(addr->addr.in4.sin_port));
3000 3000
             }
3001 3001
             break;
... ...
@@ -3006,19 +3006,19 @@ setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvp
3006 3006
                 struct in_addr ia;
3007 3007
                 memcpy(&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12],
3008 3008
                        sizeof(ia.s_addr));
3009
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);
3009
+                snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);
3010 3010
                 inet_ntop(AF_INET, &ia, buf, sizeof(buf));
3011 3011
             }
3012 3012
             else
3013 3013
             {
3014
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip6", name_prefix);
3014
+                snprintf(name_buf, sizeof(name_buf), "%s_ip6", name_prefix);
3015 3015
                 inet_ntop(AF_INET6, &addr->addr.in6.sin6_addr, buf, sizeof(buf));
3016 3016
             }
3017 3017
             setenv_str(es, name_buf, buf);
3018 3018
 
3019 3019
             if ((flags & SA_IP_PORT) && addr->addr.in6.sin6_port)
3020 3020
             {
3021
-                openvpn_snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefix);
3021
+                snprintf(name_buf, sizeof(name_buf), "%s_port", name_prefix);
3022 3022
                 setenv_int(es, name_buf, ntohs(addr->addr.in6.sin6_port));
3023 3023
             }
3024 3024
             break;
... ...
@@ -109,9 +109,10 @@ socks_username_password_auth(struct socks_proxy_info *p,
109 109
             "Authentication not possible.");
110 110
         goto cleanup;
111 111
     }
112
-    int sret = openvpn_snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s",
113
-                                (int) strlen(creds.username), creds.username,
114
-                                (int) strlen(creds.password), creds.password);
112
+
113
+    int sret = snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s",
114
+                        (int) strlen(creds.username), creds.username,
115
+                        (int) strlen(creds.password), creds.password);
115 116
     ASSERT(sret <= sizeof(to_send));
116 117
 
117 118
     size = send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
... ...
@@ -1531,16 +1531,16 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)
1531 1531
     char s2[256];
1532 1532
 
1533 1533
     s1[0] = s2[0] = 0;
1534
-    openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s",
1535
-                     prefix,
1536
-                     mbedtls_ssl_get_version(ks_ssl->ctx),
1537
-                     mbedtls_ssl_get_ciphersuite(ks_ssl->ctx));
1534
+    snprintf(s1, sizeof(s1), "%s %s, cipher %s",
1535
+             prefix,
1536
+             mbedtls_ssl_get_version(ks_ssl->ctx),
1537
+             mbedtls_ssl_get_ciphersuite(ks_ssl->ctx));
1538 1538
 
1539 1539
     cert = mbedtls_ssl_get_peer_cert(ks_ssl->ctx);
1540 1540
     if (cert != NULL)
1541 1541
     {
1542
-        openvpn_snprintf(s2, sizeof(s2), ", %u bit key",
1543
-                         (unsigned int) mbedtls_pk_get_bitlen(&cert->pk));
1542
+        snprintf(s2, sizeof(s2), ", %u bit key",
1543
+                 (unsigned int) mbedtls_pk_get_bitlen(&cert->pk));
1544 1544
     }
1545 1545
 
1546 1546
     msg(D_HANDSHAKE, "%s%s", s1, s2);
... ...
@@ -198,8 +198,8 @@ append_cipher_to_ncp_list(struct options *o, const char *ciphername)
198 198
     size_t newlen = strlen(o->ncp_ciphers) + 1 + strlen(ciphername) + 1;
199 199
     char *ncp_ciphers = gc_malloc(newlen, false, &o->gc);
200 200
 
201
-    ASSERT(openvpn_snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers,
202
-                            ciphername));
201
+    ASSERT(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers,
202
+                    ciphername));
203 203
     o->ncp_ciphers = ncp_ciphers;
204 204
 }
205 205
 
... ...
@@ -1774,7 +1774,7 @@ open_biofp(void)
1774 1774
     if (!biofp)
1775 1775
     {
1776 1776
         char fn[256];
1777
-        openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
1777
+        snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
1778 1778
         biofp = fopen(fn, "w");
1779 1779
         ASSERT(biofp);
1780 1780
         biofp_last_open = time(NULL);
... ...
@@ -2116,8 +2116,8 @@ print_pkey_details(EVP_PKEY *pkey, char *buf, size_t buflen)
2116 2116
 #endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */
2117 2117
     }
2118 2118
 
2119
-    openvpn_snprintf(buf, buflen, "%d bits %s%s",
2120
-                     EVP_PKEY_bits(pkey), type, curve);
2119
+    snprintf(buf, buflen, "%d bits %s%s",
2120
+             EVP_PKEY_bits(pkey), type, curve);
2121 2121
 }
2122 2122
 
2123 2123
 /**
... ...
@@ -2137,12 +2137,12 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)
2137 2137
     int signature_nid = X509_get_signature_nid(cert);
2138 2138
     if (signature_nid != 0)
2139 2139
     {
2140
-        openvpn_snprintf(sig, sizeof(sig), ", signature: %s",
2141
-                         OBJ_nid2sn(signature_nid));
2140
+        snprintf(sig, sizeof(sig), ", signature: %s",
2141
+                 OBJ_nid2sn(signature_nid));
2142 2142
     }
2143 2143
 
2144
-    openvpn_snprintf(buf, buflen, ", peer certificate: %s%s",
2145
-                     pkeybuf, sig);
2144
+    snprintf(buf, buflen, ", peer certificate: %s%s",
2145
+             pkeybuf, sig);
2146 2146
 
2147 2147
     EVP_PKEY_free(pkey);
2148 2148
 }
... ...
@@ -2160,8 +2160,8 @@ print_server_tempkey(SSL *ssl, char *buf, size_t buflen)
2160 2160
     char pkeybuf[128] = { 0 };
2161 2161
     print_pkey_details(pkey, pkeybuf, sizeof(pkeybuf));
2162 2162
 
2163
-    openvpn_snprintf(buf, buflen, ", peer temporary key: %s",
2164
-                     pkeybuf);
2163
+    snprintf(buf, buflen, ", peer temporary key: %s",
2164
+             pkeybuf);
2165 2165
 
2166 2166
     EVP_PKEY_free(pkey);
2167 2167
 }
... ...
@@ -2238,8 +2238,8 @@ print_peer_signature(SSL *ssl, char *buf, size_t buflen)
2238 2238
         return;
2239 2239
     }
2240 2240
 
2241
-    openvpn_snprintf(buf, buflen, ", peer signing digest/type: %s %s",
2242
-                     peer_sig, peer_sig_type);
2241
+    snprintf(buf, buflen, ", peer signing digest/type: %s %s",
2242
+             peer_sig, peer_sig_type);
2243 2243
 }
2244 2244
 
2245 2245
 
... ...
@@ -2262,11 +2262,11 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)
2262 2262
 
2263 2263
     s1[0] = s2[0] = s3[0] = s4[0] = 0;
2264 2264
     ciph = SSL_get_current_cipher(ks_ssl->ssl);
2265
-    openvpn_snprintf(s1, sizeof(s1), "%s %s, cipher %s %s",
2266
-                     prefix,
2267
-                     SSL_get_version(ks_ssl->ssl),
2268
-                     SSL_CIPHER_get_version(ciph),
2269
-                     SSL_CIPHER_get_name(ciph));
2265
+    snprintf(s1, sizeof(s1), "%s %s, cipher %s %s",
2266
+             prefix,
2267
+             SSL_get_version(ks_ssl->ssl),
2268
+             SSL_CIPHER_get_version(ciph),
2269
+             SSL_CIPHER_get_name(ciph));
2270 2270
     X509 *cert = SSL_get_peer_certificate(ks_ssl->ssl);
2271 2271
 
2272 2272
     if (cert)
... ...
@@ -421,12 +421,12 @@ verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert
421 421
     }
422 422
 
423 423
     /* export subject name string as environmental variable */
424
-    openvpn_snprintf(envname, sizeof(envname), "tls_id_%d", cert_depth);
424
+    snprintf(envname, sizeof(envname), "tls_id_%d", cert_depth);
425 425
     setenv_str(es, envname, subject);
426 426
 
427 427
 #if 0
428 428
     /* export common name string as environmental variable */
429
-    openvpn_snprintf(envname, sizeof(envname), "tls_common_name_%d", cert_depth);
429
+    snprintf(envname, sizeof(envname), "tls_common_name_%d", cert_depth);
430 430
     setenv_str(es, envname, common_name);
431 431
 #endif
432 432
 
... ...
@@ -435,24 +435,24 @@ verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert
435 435
         struct buffer sha1 = x509_get_sha1_fingerprint(peer_cert, &gc);
436 436
         struct buffer sha256 = x509_get_sha256_fingerprint(peer_cert, &gc);
437 437
 
438
-        openvpn_snprintf(envname, sizeof(envname), "tls_digest_%d", cert_depth);
438
+        snprintf(envname, sizeof(envname), "tls_digest_%d", cert_depth);
439 439
         setenv_str(es, envname,
440 440
                    format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &gc));
441 441
 
442
-        openvpn_snprintf(envname, sizeof(envname), "tls_digest_sha256_%d",
443
-                         cert_depth);
442
+        snprintf(envname, sizeof(envname), "tls_digest_sha256_%d",
443
+                 cert_depth);
444 444
         setenv_str(es, envname,
445 445
                    format_hex_ex(BPTR(&sha256), BLEN(&sha256), 0, 1, ":", &gc));
446 446
     }
447 447
 
448 448
     /* export serial number as environmental variable */
449 449
     serial = backend_x509_get_serial(peer_cert, &gc);
450
-    openvpn_snprintf(envname, sizeof(envname), "tls_serial_%d", cert_depth);
450
+    snprintf(envname, sizeof(envname), "tls_serial_%d", cert_depth);
451 451
     setenv_str(es, envname, serial);
452 452
 
453 453
     /* export serial number in hex as environmental variable */
454 454
     serial = backend_x509_get_serial_hex(peer_cert, &gc);
455
-    openvpn_snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert_depth);
455
+    snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert_depth);
456 456
     setenv_str(es, envname, serial);
457 457
 
458 458
     gc_free(&gc);
... ...
@@ -569,7 +569,7 @@ verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert,
569 569
         goto cleanup;
570 570
     }
571 571
 
572
-    if (!openvpn_snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR, serial))
572
+    if (!snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR, serial))
573 573
     {
574 574
         msg(D_HANDSHAKE, "VERIFY CRL: filename overflow");
575 575
         goto cleanup;
... ...
@@ -938,9 +938,9 @@ key_state_check_auth_pending_file(struct auth_deferred_status *ads,
938 938
             if (!check_auth_pending_method(multi->peer_info, pending_method))
939 939
             {
940 940
                 char buf[128];
941
-                openvpn_snprintf(buf, sizeof(buf),
942
-                                 "Authentication failed, required pending auth "
943
-                                 "method '%s' not supported", pending_method);
941
+                snprintf(buf, sizeof(buf),
942
+                         "Authentication failed, required pending auth "
943
+                         "method '%s' not supported", pending_method);
944 944
                 auth_set_client_reason(multi, buf);
945 945
                 msg(M_INFO, "Client does not supported auth pending method "
946 946
                     "'%s'", pending_method);
... ...
@@ -86,8 +86,8 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
86 86
         char *serial = backend_x509_get_serial(cert, &gc);
87 87
 
88 88
         ret = mbedtls_x509_crt_verify_info(errstr, sizeof(errstr)-1, "", *flags);
89
-        if (ret <= 0 && !openvpn_snprintf(errstr, sizeof(errstr),
90
-                                          "Could not retrieve error string, flags=%" PRIx32, *flags))
89
+        if (ret <= 0 && !snprintf(errstr, sizeof(errstr),
90
+                                  "Could not retrieve error string, flags=%" PRIx32, *flags))
91 91
         {
92 92
             errstr[0] = '\0';
93 93
         }
... ...
@@ -307,7 +307,7 @@ do_setenv_x509(struct env_set *es, const char *name, char *value, int depth)
307 307
     name_expand_size = 64 + strlen(name);
308 308
     name_expand = (char *) malloc(name_expand_size);
309 309
     check_malloc_return(name_expand);
310
-    openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name);
310
+    snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name);
311 311
     setenv_str(es, name_expand, value);
312 312
     free(name_expand);
313 313
 }
... ...
@@ -431,13 +431,13 @@ x509_setenv(struct env_set *es, int cert_depth, mbedtls_x509_crt *cert)
431 431
 
432 432
         if (0 == mbedtls_oid_get_attr_short_name(&name->oid, &shortname) )
433 433
         {
434
-            openvpn_snprintf(name_expand, sizeof(name_expand), "X509_%d_%s",
435
-                             cert_depth, shortname);
434
+            snprintf(name_expand, sizeof(name_expand), "X509_%d_%s",
435
+                     cert_depth, shortname);
436 436
         }
437 437
         else
438 438
         {
439
-            openvpn_snprintf(name_expand, sizeof(name_expand), "X509_%d_\?\?",
440
-                             cert_depth);
439
+            snprintf(name_expand, sizeof(name_expand), "X509_%d_\?\?",
440
+                     cert_depth);
441 441
         }
442 442
 
443 443
         for (i = 0; i < name->val.len; i++)
... ...
@@ -279,7 +279,7 @@ backend_x509_get_username(char *common_name, int cn_len,
279 279
             gc_free(&gc);
280 280
             return FAILURE;
281 281
         }
282
-        openvpn_snprintf(common_name, cn_len, "0x%s", serial);
282
+        snprintf(common_name, cn_len, "0x%s", serial);
283 283
         gc_free(&gc);
284 284
     }
285 285
     else
... ...
@@ -454,7 +454,7 @@ do_setenv_x509(struct env_set *es, const char *name, char *value, int depth)
454 454
     name_expand_size = 64 + strlen(name);
455 455
     name_expand = (char *) malloc(name_expand_size);
456 456
     check_malloc_return(name_expand);
457
-    openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name);
457
+    snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name);
458 458
     setenv_str(es, name_expand, value);
459 459
     free(name_expand);
460 460
 }
... ...
@@ -597,8 +597,8 @@ x509_setenv(struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_cert)
597 597
         name_expand_size = 64 + strlen(objbuf);
598 598
         name_expand = (char *) malloc(name_expand_size);
599 599
         check_malloc_return(name_expand);
600
-        openvpn_snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth,
601
-                         objbuf);
600
+        snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth,
601
+                 objbuf);
602 602
         string_mod(name_expand, CC_PRINT, CC_CRLF, '_');
603 603
         string_mod((char *)buf, CC_PRINT, CC_CRLF, '_');
604 604
         setenv_str_incr(es, name_expand, (char *)buf);
... ...
@@ -574,8 +574,8 @@ tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx,
574 574
     }
575 575
 
576 576
     char metadata_type_str[4] = { 0 }; /* Max value: 255 */
577
-    openvpn_snprintf(metadata_type_str, sizeof(metadata_type_str),
578
-                     "%i", (uint8_t) metadata_type);
577
+    snprintf(metadata_type_str, sizeof(metadata_type_str),
578
+             "%i", (uint8_t) metadata_type);
579 579
     struct env_set *es = env_set_create(NULL);
580 580
     setenv_str(es, "script_type", "tls-crypt-v2-verify");
581 581
     setenv_str(es, "metadata_type", metadata_type_str);
... ...
@@ -1114,8 +1114,8 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu,
1114 1114
 #elif defined(TARGET_ANDROID)
1115 1115
     char out6[64];
1116 1116
 
1117
-    openvpn_snprintf(out6, sizeof(out6), "%s/%d %d",
1118
-                     ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu);
1117
+    snprintf(out6, sizeof(out6), "%s/%d %d",
1118
+             ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu);
1119 1119
     management_android_control(management, "IFCONFIG6", out6);
1120 1120
 #elif defined(TARGET_SOLARIS)
1121 1121
     argv_printf(&argv, "%s %s inet6 unplumb", IFCONFIG_PATH, ifname);
... ...
@@ -1362,8 +1362,8 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1362 1362
             top = "undef";
1363 1363
     }
1364 1364
 
1365
-    openvpn_snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local,
1366
-                     ifconfig_remote_netmask, tun_mtu, top);
1365
+    snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local,
1366
+             ifconfig_remote_netmask, tun_mtu, top);
1367 1367
     management_android_control(management, "IFCONFIG", out);
1368 1368
 
1369 1369
 #elif defined(TARGET_SOLARIS)
... ...
@@ -1912,7 +1912,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
1912 1912
          */
1913 1913
         if (dev_node)
1914 1914
         {
1915
-            openvpn_snprintf(tunname, sizeof(tunname), "%s", dev_node);
1915
+            snprintf(tunname, sizeof(tunname), "%s", dev_node);
1916 1916
         }
1917 1917
         else
1918 1918
         {
... ...
@@ -1926,10 +1926,10 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
1926 1926
             {
1927 1927
                 for (int i = 0; i < 256; ++i)
1928 1928
                 {
1929
-                    openvpn_snprintf(tunname, sizeof(tunname),
1930
-                                     "/dev/%s%d", dev, i);
1931
-                    openvpn_snprintf(dynamic_name, sizeof(dynamic_name),
1932
-                                     "%s%d", dev, i);
1929
+                    snprintf(tunname, sizeof(tunname),
1930
+                             "/dev/%s%d", dev, i);
1931
+                    snprintf(dynamic_name, sizeof(dynamic_name),
1932
+                             "%s%d", dev, i);
1933 1933
                     if ((tt->fd = open(tunname, O_RDWR)) > 0)
1934 1934
                     {
1935 1935
                         dynamic_opened = true;
... ...
@@ -1947,7 +1947,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
1947 1947
              */
1948 1948
             else
1949 1949
             {
1950
-                openvpn_snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
1950
+                snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
1951 1951
             }
1952 1952
         }
1953 1953
 
... ...
@@ -2002,8 +2002,8 @@ open_tun_dco_generic(const char *dev, const char *dev_type,
2002 2002
     {
2003 2003
         for (int i = 0; i < 256; ++i)
2004 2004
         {
2005
-            openvpn_snprintf(dynamic_name, sizeof(dynamic_name),
2006
-                             "%s%d", dev, i);
2005
+            snprintf(dynamic_name, sizeof(dynamic_name),
2006
+                     "%s%d", dev, i);
2007 2007
             int ret = open_tun_dco(tt, ctx, dynamic_name);
2008 2008
             if (ret == 0)
2009 2009
             {
... ...
@@ -2519,7 +2519,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2519 2519
     tt->actual_name = (char *) malloc(32);
2520 2520
     check_malloc_return(tt->actual_name);
2521 2521
 
2522
-    openvpn_snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
2522
+    snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
2523 2523
 
2524 2524
     if (tt->type == DEV_TYPE_TAP)
2525 2525
     {
... ...
@@ -3509,7 +3509,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3509 3509
         int i;
3510 3510
         for (i = 0; i<99; i++)
3511 3511
         {
3512
-            openvpn_snprintf(tunname, sizeof(tunname), "/dev/tap%d", i);
3512
+            snprintf(tunname, sizeof(tunname), "/dev/tap%d", i);
3513 3513
             if (access( tunname, F_OK ) < 0 && errno == ENOENT)
3514 3514
             {
3515 3515
                 break;
... ...
@@ -3520,7 +3520,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3520 3520
             msg( M_FATAL, "cannot find unused tap device" );
3521 3521
         }
3522 3522
 
3523
-        openvpn_snprintf( dynamic_name, sizeof(dynamic_name), "tap%d", i );
3523
+        snprintf( dynamic_name, sizeof(dynamic_name), "tap%d", i );
3524 3524
         dev = dynamic_name;
3525 3525
     }
3526 3526
     else                                        /* name given, sanity check */
... ...
@@ -3536,7 +3536,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3536 3536
             msg( M_FATAL, "TAP device name must be '--dev tapNNNN'" );
3537 3537
         }
3538 3538
 
3539
-        openvpn_snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
3539
+        snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
3540 3540
     }
3541 3541
 
3542 3542
     /* pre-existing device?
... ...
@@ -3956,8 +3956,8 @@ get_tap_reg(struct gc_arena *gc)
3956 3956
                 ADAPTER_KEY);
3957 3957
         }
3958 3958
 
3959
-        openvpn_snprintf(unit_string, sizeof(unit_string), "%s\\%s",
3960
-                         ADAPTER_KEY, enum_name);
3959
+        snprintf(unit_string, sizeof(unit_string), "%s\\%s",
3960
+                 ADAPTER_KEY, enum_name);
3961 3961
 
3962 3962
         status = RegOpenKeyEx(
3963 3963
             HKEY_LOCAL_MACHINE,
... ...
@@ -4098,9 +4098,9 @@ get_panel_reg(struct gc_arena *gc)
4098 4098
                 NETWORK_CONNECTIONS_KEY);
4099 4099
         }
4100 4100
 
4101
-        openvpn_snprintf(connection_string, sizeof(connection_string),
4102
-                         "%s\\%s\\Connection",
4103
-                         NETWORK_CONNECTIONS_KEY, enum_name);
4101
+        snprintf(connection_string, sizeof(connection_string),
4102
+                 "%s\\%s\\Connection",
4103
+                 NETWORK_CONNECTIONS_KEY, enum_name);
4104 4104
 
4105 4105
         status = RegOpenKeyEx(
4106 4106
             HKEY_LOCAL_MACHINE,
... ...
@@ -4984,7 +4984,7 @@ get_adapter_index_method_1(const char *guid)
4984 4984
     DWORD index;
4985 4985
     ULONG aindex;
4986 4986
     wchar_t wbuf[256];
4987
-    openvpn_swprintf(wbuf, SIZE(wbuf), L"\\DEVICE\\TCPIP_%hs", guid);
4987
+    swprintf(wbuf, SIZE(wbuf), L"\\DEVICE\\TCPIP_%hs", guid);
4988 4988
     if (GetAdapterIndex(wbuf, &aindex) != NO_ERROR)
4989 4989
     {
4990 4990
         index = TUN_ADAPTER_INDEX_INVALID;
... ...
@@ -5164,10 +5164,10 @@ tap_allow_nonadmin_access(const char *dev_node)
5164 5164
         }
5165 5165
 
5166 5166
         /* Open Windows TAP-Windows adapter */
5167
-        openvpn_snprintf(device_path, sizeof(device_path), "%s%s%s",
5168
-                         USERMODEDEVICEDIR,
5169
-                         device_guid,
5170
-                         TAP_WIN_SUFFIX);
5167
+        snprintf(device_path, sizeof(device_path), "%s%s%s",
5168
+                 USERMODEDEVICEDIR,
5169
+                 device_guid,
5170
+                 TAP_WIN_SUFFIX);
5171 5171
 
5172 5172
         hand = CreateFile(
5173 5173
             device_path,
... ...
@@ -5208,10 +5208,10 @@ tap_allow_nonadmin_access(const char *dev_node)
5208 5208
             }
5209 5209
 
5210 5210
             /* Open Windows TAP-Windows adapter */
5211
-            openvpn_snprintf(device_path, sizeof(device_path), "%s%s%s",
5212
-                             USERMODEDEVICEDIR,
5213
-                             device_guid,
5214
-                             TAP_WIN_SUFFIX);
5211
+            snprintf(device_path, sizeof(device_path), "%s%s%s",
5212
+                     USERMODEDEVICEDIR,
5213
+                     device_guid,
5214
+                     TAP_WIN_SUFFIX);
5215 5215
 
5216 5216
             hand = CreateFile(
5217 5217
                 device_path,
... ...
@@ -6607,10 +6607,10 @@ tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct dev
6607 6607
     else
6608 6608
     {
6609 6609
         /* Open TAP-Windows */
6610
-        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
6611
-                         USERMODEDEVICEDIR,
6612
-                         device_guid,
6613
-                         TAP_WIN_SUFFIX);
6610
+        snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
6611
+                 USERMODEDEVICEDIR,
6612
+                 device_guid,
6613
+                 TAP_WIN_SUFFIX);
6614 6614
         path = tuntap_device_path;
6615 6615
     }
6616 6616
 
... ...
@@ -885,8 +885,8 @@ env_block(const struct env_set *es)
885 885
     char force_path[256];
886 886
     char *sysroot = get_win_sys_path();
887 887
 
888
-    if (!openvpn_snprintf(force_path, sizeof(force_path), "PATH=%s\\System32;%s;%s\\System32\\Wbem",
889
-                          sysroot, sysroot, sysroot))
888
+    if (!snprintf(force_path, sizeof(force_path), "PATH=%s\\System32;%s;%s\\System32\\Wbem",
889
+                  sysroot, sysroot, sysroot))
890 890
     {
891 891
         msg(M_WARN, "env_block: default path truncated to %s", force_path);
892 892
     }
... ...
@@ -1483,26 +1483,11 @@ send_msg_iservice(HANDLE pipe, const void *data, size_t size,
1483 1483
 }
1484 1484
 
1485 1485
 bool
1486
-openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...)
1487
-{
1488
-    va_list arglist;
1489
-    int len = -1;
1490
-    if (size > 0)
1491
-    {
1492
-        va_start(arglist, format);
1493
-        len = vswprintf(str, size, format, arglist);
1494
-        va_end(arglist);
1495
-        str[size - 1] = L'\0';
1496
-    }
1497
-    return (len >= 0 && len < size);
1498
-}
1499
-
1500
-bool
1501 1486
 get_openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size)
1502 1487
 {
1503 1488
     WCHAR reg_path[256];
1504 1489
     HKEY hkey;
1505
-    openvpn_swprintf(reg_path, _countof(reg_path), L"SOFTWARE\\" PACKAGE_NAME);
1490
+    swprintf(reg_path, _countof(reg_path), L"SOFTWARE\\" PACKAGE_NAME);
1506 1491
 
1507 1492
     LONG status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_READ, &hkey);
1508 1493
     if (status != ERROR_SUCCESS)
... ...
@@ -1528,7 +1513,7 @@ set_openssl_env_vars()
1528 1528
         /* if we cannot find installation path from the registry,
1529 1529
          * use Windows directory as a fallback
1530 1530
          */
1531
-        openvpn_swprintf(install_path, _countof(install_path), L"%ls", ssl_fallback_dir);
1531
+        swprintf(install_path, _countof(install_path), L"%ls", ssl_fallback_dir);
1532 1532
     }
1533 1533
 
1534 1534
     if ((install_path[wcslen(install_path) - 1]) == L'\\')
... ...
@@ -1553,7 +1538,7 @@ set_openssl_env_vars()
1553 1553
         if (size == 0)
1554 1554
         {
1555 1555
             WCHAR val[MAX_PATH] = {0};
1556
-            openvpn_swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, ossl_env[i].value);
1556
+            swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, ossl_env[i].value);
1557 1557
             _wputenv_s(ossl_env[i].name, val);
1558 1558
         }
1559 1559
     }
... ...
@@ -319,14 +319,6 @@ bool send_msg_iservice(HANDLE pipe, const void *data, size_t size,
319 319
 int
320 320
 openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags);
321 321
 
322
-/*
323
- * openvpn_swprintf() is currently only used by Windows code paths
324
- * and when enabled for all platforms it will currently break older
325
- * OpenBSD versions lacking vswprintf(3) support in their libc.
326
- */
327
-bool
328
-openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...);
329
-
330 322
 /* Sleep that can be interrupted by signals and exit event */
331 323
 void win32_sleep(const int n);
332 324
 
... ...
@@ -205,7 +205,7 @@ xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen,
205 205
         }
206 206
         else
207 207
         {
208
-            openvpn_snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=%s", alg.mdname);
208
+            snprintf(alg_str, sizeof(alg_str), "ECDSA,hashalg=%s", alg.mdname);
209 209
         }
210 210
     }
211 211
     else if (!strcmp(alg.keytype, "ED448") || !strcmp(alg.keytype, "ED25519"))
... ...
@@ -229,8 +229,8 @@ xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen,
229 229
         /* For undigested message, add hashalg=digest parameter */
230 230
         else
231 231
         {
232
-            openvpn_snprintf(alg_str, sizeof(alg_str), "%s,hashalg=%s",
233
-                             "RSA_PKCS1_PADDING", alg.mdname);
232
+            snprintf(alg_str, sizeof(alg_str), "%s,hashalg=%s",
233
+                     "RSA_PKCS1_PADDING", alg.mdname);
234 234
         }
235 235
     }
236 236
     else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPADDING)
... ...
@@ -240,8 +240,8 @@ xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen,
240 240
     }
241 241
     else if (!strcmp(alg.padmode, "pss") && (flags & MF_EXTERNAL_KEY_PSSPAD))
242 242
     {
243
-        openvpn_snprintf(alg_str, sizeof(alg_str), "%s,hashalg=%s,saltlen=%s",
244
-                         "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen);
243
+        snprintf(alg_str, sizeof(alg_str), "%s,hashalg=%s,saltlen=%s",
244
+                 "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen);
245 245
     }
246 246
     else
247 247
     {
... ...
@@ -27,36 +27,6 @@
27 27
 LPCTSTR service_instance = TEXT("");
28 28
 static wchar_t win_sys_path[MAX_PATH];
29 29
 
30
-/*
31
- * These are necessary due to certain buggy implementations of (v)snprintf,
32
- * that don't guarantee null termination for size > 0.
33
- */
34
-BOOL
35
-openvpn_vswprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
36
-{
37
-    int len = -1;
38
-    if (size > 0)
39
-    {
40
-        len = vswprintf_s(str, size, format, arglist);
41
-        str[size - 1] = 0;
42
-    }
43
-    return (len >= 0 && (size_t)len < size);
44
-}
45
-
46
-BOOL
47
-openvpn_swprintf(LPTSTR str, size_t size, LPCTSTR format, ...)
48
-{
49
-    va_list arglist;
50
-    BOOL res = FALSE;
51
-    if (size > 0)
52
-    {
53
-        va_start(arglist, format);
54
-        res = openvpn_vswprintf(str, size, format, arglist);
55
-        va_end(arglist);
56
-    }
57
-    return res;
58
-}
59
-
60 30
 static DWORD
61 31
 GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_value)
62 32
 {
... ...
@@ -66,7 +36,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v
66 66
     if (status == ERROR_FILE_NOT_FOUND && default_value)
67 67
     {
68 68
         size_t len = size/sizeof(data[0]);
69
-        if (openvpn_swprintf(data, len, default_value))
69
+        if (swprintf(data, len, default_value))
70 70
         {
71 71
             status = ERROR_SUCCESS;
72 72
         }
... ...
@@ -93,7 +63,7 @@ GetOpenvpnSettings(settings_t *s)
93 93
     TCHAR install_path[MAX_PATH];
94 94
     TCHAR default_value[MAX_PATH];
95 95
 
96
-    openvpn_swprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKAGE_NAME "%ls"), service_instance);
96
+    swprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKAGE_NAME "%ls"), service_instance);
97 97
 
98 98
     LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_READ, &key);
99 99
     if (status != ERROR_SUCCESS)
... ...
@@ -110,15 +80,15 @@ GetOpenvpnSettings(settings_t *s)
110 110
         goto out;
111 111
     }
112 112
 
113
-    openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\bin\\openvpn.exe"),
114
-                     install_path);
113
+    swprintf(default_value, _countof(default_value), TEXT("%ls\\bin\\openvpn.exe"),
114
+             install_path);
115 115
     error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), default_value);
116 116
     if (error != ERROR_SUCCESS)
117 117
     {
118 118
         goto out;
119 119
     }
120 120
 
121
-    openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\config"), install_path);
121
+    swprintf(default_value, _countof(default_value), TEXT("%ls\\config"), install_path);
122 122
     error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir),
123 123
                          default_value);
124 124
     if (error != ERROR_SUCCESS)
... ...
@@ -133,7 +103,7 @@ GetOpenvpnSettings(settings_t *s)
133 133
         goto out;
134 134
     }
135 135
 
136
-    openvpn_swprintf(default_value, _countof(default_value), TEXT("%ls\\log"), install_path);
136
+    swprintf(default_value, _countof(default_value), TEXT("%ls\\log"), install_path);
137 137
     error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), default_value);
138 138
     if (error != ERROR_SUCCESS)
139 139
     {
... ...
@@ -229,7 +199,7 @@ GetLastErrorText()
229 229
     else
230 230
     {
231 231
         tmp[wcslen(tmp) - 2] = TEXT('\0'); /* remove CR/LF characters */
232
-        openvpn_swprintf(buf, _countof(buf), TEXT("%ls (0x%x)"), tmp, error);
232
+        swprintf(buf, _countof(buf), TEXT("%ls (0x%x)"), tmp, error);
233 233
     }
234 234
 
235 235
     if (tmp)
... ...
@@ -259,12 +229,12 @@ MsgToEventLog(DWORD flags, LPCTSTR format, ...)
259 259
     hEventSource = RegisterEventSource(NULL, APPNAME);
260 260
     if (hEventSource != NULL)
261 261
     {
262
-        openvpn_swprintf(msg[0], _countof(msg[0]),
263
-                         TEXT("%ls%ls%ls: %ls"), APPNAME, service_instance,
264
-                         (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), err_msg);
262
+        swprintf(msg[0], _countof(msg[0]),
263
+                 TEXT("%ls%ls%ls: %ls"), APPNAME, service_instance,
264
+                 (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), err_msg);
265 265
 
266 266
         va_start(arglist, format);
267
-        openvpn_vswprintf(msg[1], _countof(msg[1]), format, arglist);
267
+        vswprintf(msg[1], _countof(msg[1]), format, arglist);
268 268
         va_end(arglist);
269 269
 
270 270
         const TCHAR *mesg[] = { msg[0], msg[1] };
... ...
@@ -311,7 +311,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events)
311 311
      * Same format as error messages (3 line string) with error = 0 in
312 312
      * 0x%08x format, PID on line 2 and a description "Process ID" on line 3
313 313
      */
314
-    openvpn_swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, msg);
314
+    swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%ls", 0, pid, msg);
315 315
 
316 316
     WritePipeAsync(pipe, buf, (DWORD)(wcslen(buf) * 2), count, events);
317 317
 }
... ...
@@ -385,9 +385,9 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, WCHAR *
385 385
 
386 386
     if (!argv)
387 387
     {
388
-        openvpn_swprintf(errmsg, capacity,
389
-                         L"Cannot validate options: CommandLineToArgvW failed with error = 0x%08x",
390
-                         GetLastError());
388
+        swprintf(errmsg, capacity,
389
+                 L"Cannot validate options: CommandLineToArgvW failed with error = 0x%08x",
390
+                 GetLastError());
391 391
         goto out;
392 392
     }
393 393
 
... ...
@@ -407,8 +407,8 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, WCHAR *
407 407
 
408 408
         if (!CheckOption(workdir, 2, argv_tmp, &settings))
409 409
         {
410
-            openvpn_swprintf(errmsg, capacity, msg1, argv[0], workdir,
411
-                             settings.ovpn_admin_group);
410
+            swprintf(errmsg, capacity, msg1, argv[0], workdir,
411
+                     settings.ovpn_admin_group);
412 412
         }
413 413
         goto out;
414 414
     }
... ...
@@ -424,13 +424,13 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, WCHAR *
424 424
         {
425 425
             if (wcscmp(L"--config", argv[i]) == 0 && argc-i > 1)
426 426
             {
427
-                openvpn_swprintf(errmsg, capacity, msg1, argv[i+1], workdir,
428
-                                 settings.ovpn_admin_group);
427
+                swprintf(errmsg, capacity, msg1, argv[i+1], workdir,
428
+                         settings.ovpn_admin_group);
429 429
             }
430 430
             else
431 431
             {
432
-                openvpn_swprintf(errmsg, capacity, msg2, argv[i],
433
-                                 settings.ovpn_admin_group);
432
+                swprintf(errmsg, capacity, msg2, argv[i],
433
+                         settings.ovpn_admin_group);
434 434
             }
435 435
             goto out;
436 436
         }
... ...
@@ -985,7 +985,7 @@ RegisterDNS(LPVOID unused)
985 985
 
986 986
     HANDLE wait_handles[2] = {rdns_semaphore, exit_event};
987 987
 
988
-    openvpn_swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path(), L"ipconfig.exe");
988
+    swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path(), L"ipconfig.exe");
989 989
 
990 990
     if (WaitForMultipleObjects(2, wait_handles, FALSE, timeout) == WAIT_OBJECT_0)
991 991
     {
... ...
@@ -1064,7 +1064,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam
1064 1064
     }
1065 1065
 
1066 1066
     /* Path of netsh */
1067
-    openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1067
+    swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1068 1068
 
1069 1069
     /* cmd template:
1070 1070
      * netsh interface $proto $action dns $if_name $addr [validate=no]
... ...
@@ -1080,7 +1080,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam
1080 1080
         goto out;
1081 1081
     }
1082 1082
 
1083
-    openvpn_swprintf(cmdline, ncmdline, fmt, proto, action, if_name, addr);
1083
+    swprintf(cmdline, ncmdline, fmt, proto, action, if_name, addr);
1084 1084
 
1085 1085
     if (IsWindows7OrGreater())
1086 1086
     {
... ...
@@ -1124,7 +1124,7 @@ netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_t *add
1124 1124
     }
1125 1125
 
1126 1126
     /* Path of netsh */
1127
-    openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1127
+    swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1128 1128
 
1129 1129
     /* cmd template:
1130 1130
      * netsh interface ip $action wins $if_name $static $addr
... ...
@@ -1141,7 +1141,7 @@ netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_t *add
1141 1141
         goto out;
1142 1142
     }
1143 1143
 
1144
-    openvpn_swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr);
1144
+    swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr);
1145 1145
 
1146 1146
     err = ExecCommand(argv0, cmdline, timeout);
1147 1147
 
... ...
@@ -1167,7 +1167,7 @@ wmic_nicconfig_cmd(const wchar_t *action, const NET_IFINDEX if_index,
1167 1167
     wchar_t *cmdline = NULL;
1168 1168
     int timeout = 10000; /* in msec */
1169 1169
 
1170
-    openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"wbem\\wmic.exe");
1170
+    swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"wbem\\wmic.exe");
1171 1171
 
1172 1172
     const wchar_t *fmt;
1173 1173
     /* comma separated list must be enclosed in parenthesis */
... ...
@@ -1188,8 +1188,8 @@ wmic_nicconfig_cmd(const wchar_t *action, const NET_IFINDEX if_index,
1188 1188
         return ERROR_OUTOFMEMORY;
1189 1189
     }
1190 1190
 
1191
-    openvpn_swprintf(cmdline, ncmdline, fmt, if_index, action,
1192
-                     data ? data : L"");
1191
+    swprintf(cmdline, ncmdline, fmt, if_index, action,
1192
+             data ? data : L"");
1193 1193
     err = ExecCommand(argv0, cmdline, timeout);
1194 1194
 
1195 1195
     free(cmdline);
... ...
@@ -1453,7 +1453,7 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp)
1453 1453
     wchar_t argv0[MAX_PATH];
1454 1454
 
1455 1455
     /* Path of netsh */
1456
-    openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1456
+    swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L"netsh.exe");
1457 1457
 
1458 1458
     /* cmd template:
1459 1459
      * netsh interface ipv4 set address name=$if_index source=dhcp
... ...
@@ -1471,7 +1471,7 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp)
1471 1471
         return err;
1472 1472
     }
1473 1473
 
1474
-    openvpn_swprintf(cmdline, ncmdline, fmt, dhcp->iface.index);
1474
+    swprintf(cmdline, ncmdline, fmt, dhcp->iface.index);
1475 1475
 
1476 1476
     err = ExecCommand(argv0, cmdline, timeout);
1477 1477
 
... ...
@@ -1970,8 +1970,8 @@ RunOpenvpn(LPVOID p)
1970 1970
         goto out;
1971 1971
     }
1972 1972
 
1973
-    openvpn_swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name),
1974
-                     TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service_%lu"), service_instance, GetCurrentThreadId());
1973
+    swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name),
1974
+             TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service_%lu"), service_instance, GetCurrentThreadId());
1975 1975
     ovpn_pipe = CreateNamedPipe(ovpn_pipe_name,
1976 1976
                                 PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED,
1977 1977
                                 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 128, 128, 0, NULL);
... ...
@@ -2003,8 +2003,11 @@ RunOpenvpn(LPVOID p)
2003 2003
         ReturnLastError(pipe, L"malloc");
2004 2004
         goto out;
2005 2005
     }
2006
-    openvpn_swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %" PRIuPTR,
2007
-                     sud.options, svc_pipe);
2006
+    /* there seem to be no common printf specifier that works on all
2007
+     * mingw/msvc platforms without trickery, so convert to void* and use
2008
+     * PRIuPTR to print that as best compromise */
2009
+    swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %" PRIuPTR,
2010
+             sud.options, (uintptr_t)svc_pipe);
2008 2011
 
2009 2012
     if (!CreateEnvironmentBlock(&user_env, imp_token, FALSE))
2010 2013
     {
... ...
@@ -2079,8 +2082,8 @@ RunOpenvpn(LPVOID p)
2079 2079
     else if (exit_code != 0)
2080 2080
     {
2081 2081
         WCHAR buf[256];
2082
-        openvpn_swprintf(buf, _countof(buf),
2083
-                         L"OpenVPN exited with error: exit code = %lu", exit_code);
2082
+        swprintf(buf, _countof(buf),
2083
+                 L"OpenVPN exited with error: exit code = %lu", exit_code);
2084 2084
         ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event);
2085 2085
     }
2086 2086
     Undo(&undo_lists);
... ...
@@ -2174,7 +2177,7 @@ CreateClientPipeInstance(VOID)
2174 2174
         initialized = TRUE;
2175 2175
     }
2176 2176
 
2177
-    openvpn_swprintf(pipe_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service"), service_instance);
2177
+    swprintf(pipe_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\" PACKAGE "%ls\\service"), service_instance);
2178 2178
     pipe = CreateNamedPipe(pipe_name, flags,
2179 2179
                            PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS,
2180 2180
                            PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, NULL);
... ...
@@ -81,12 +81,6 @@ VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv);
81 81
 
82 82
 VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
83 83
 
84
-BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
85
-
86
-BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
87
-
88
-BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...);
89
-
90 84
 DWORD GetOpenvpnSettings(settings_t *s);
91 85
 
92 86
 BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
... ...
@@ -68,7 +68,7 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)
68 68
     /* convert fname to full path */
69 69
     if (PathIsRelativeW(fname) )
70 70
     {
71
-        openvpn_swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname);
71
+        swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname);
72 72
         config_file = tmp;
73 73
     }
74 74
     else
... ...
@@ -354,6 +354,56 @@ test_character_class(void **state)
354 354
     assert_string_equal(buf, "There is a .'nice.' \"1234\" [.] year old .tree!");
355 355
 }
356 356
 
357
+static void
358
+test_snprintf(void **state)
359
+{
360
+    /* we used to have a custom openvpn_snprintf function because some
361
+     * OS (the comment did not specify which) did not always put the
362
+     * null byte there. So we unit test this to be sure.
363
+     *
364
+     * This probably refers to the MSVC behaviour, see also
365
+     * https://stackoverflow.com/questions/7706936/is-snprintf-always-null-terminating
366
+     */
367
+
368
+    /* Instead of trying to trick the compiler here, disable the warnings
369
+     * for this unit test. We know that the results will be truncated
370
+     * and we want to test that */
371
+#if defined(__GNUC__)
372
+/* some clang version do not understand -Wformat-truncation, so ignore the
373
+ * warning to avoid warnings/errors (-Werror) about unknown pragma/option */
374
+#if defined(__clang__)
375
+#pragma clang diagnostic push
376
+#pragma clang diagnostic ignored "-Wunknown-warning-option"
377
+#endif
378
+#pragma GCC diagnostic push
379
+#pragma GCC diagnostic ignored "-Wformat-truncation"
380
+#endif
381
+
382
+    char buf[10] = { 'a' };
383
+    int ret = 0;
384
+
385
+    ret = snprintf(buf, sizeof(buf), "0123456789abcde");
386
+    assert_int_equal(ret, 15);
387
+    assert_int_equal(buf[9], '\0');
388
+
389
+    memset(buf, 'b', sizeof(buf));
390
+    ret = snprintf(buf, sizeof(buf), "- %d - %d -", 77, 88);
391
+    assert_int_equal(ret, 11);
392
+    assert_int_equal(buf[9], '\0');
393
+
394
+    memset(buf, 'c', sizeof(buf));
395
+    ret = snprintf(buf, sizeof(buf), "- %8.2f", 77.8899);
396
+    assert_int_equal(ret, 10);
397
+    assert_int_equal(buf[9], '\0');
398
+
399
+#if defined(__GNUC__)
400
+#pragma GCC diagnostic pop
401
+#if defined(__clang__)
402
+#pragma clang diagnostic pop
403
+#endif
404
+#endif
405
+}
406
+
357 407
 int
358 408
 main(void)
359 409
 {
... ...
@@ -387,6 +437,7 @@ main(void)
387 387
         cmocka_unit_test(test_buffer_free_gc_two),
388 388
         cmocka_unit_test(test_buffer_gc_realloc),
389 389
         cmocka_unit_test(test_character_class),
390
+        cmocka_unit_test(test_snprintf)
390 391
     };
391 392
 
392 393
     return cmocka_run_group_tests_name("buffer", tests, NULL, NULL);
... ...
@@ -271,7 +271,7 @@ test_find_cert_bythumb(void **state)
271 271
 
272 272
     for (struct test_cert *c = certs; c->cert; c++)
273 273
     {
274
-        openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
274
+        snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
275 275
         ctx = find_certificate_in_store(select_string, user_store);
276 276
         if (ctx)
277 277
         {
... ...
@@ -304,7 +304,7 @@ test_find_cert_byname(void **state)
304 304
 
305 305
     for (struct test_cert *c = certs; c->cert; c++)
306 306
     {
307
-        openvpn_snprintf(select_string, sizeof(select_string), "SUBJ:%s", c->cname);
307
+        snprintf(select_string, sizeof(select_string), "SUBJ:%s", c->cname);
308 308
         ctx = find_certificate_in_store(select_string, user_store);
309 309
         /* In this case we expect a successful return as there is at least one valid
310 310
          * cert that matches the common name. But the returned cert may not exactly match
... ...
@@ -337,7 +337,7 @@ test_find_cert_byissuer(void **state)
337 337
 
338 338
     for (struct test_cert *c = certs; c->cert; c++)
339 339
     {
340
-        openvpn_snprintf(select_string, sizeof(select_string), "ISSUER:%s", c->issuer);
340
+        snprintf(select_string, sizeof(select_string), "ISSUER:%s", c->issuer);
341 341
         ctx = find_certificate_in_store(select_string, user_store);
342 342
         /* In this case we expect a successful return as there is at least one valid
343 343
          * cert that matches the issuer. But the returned cert may not exactly match
... ...
@@ -411,7 +411,7 @@ test_cryptoapi_sign(void **state)
411 411
         {
412 412
             continue;
413 413
         }
414
-        openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
414
+        snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
415 415
         if (Load_CryptoAPI_certificate(select_string, &x509, &privkey) != 1)
416 416
         {
417 417
             fail_msg("Load_CryptoAPI_certificate failed: <%s>", c->friendly_name);
... ...
@@ -446,7 +446,7 @@ test_ssl_ctx_use_cryptoapicert(void **state)
446 446
         SSL_CTX *ssl_ctx = SSL_CTX_new_ex(tls_libctx, NULL, SSLv23_client_method());
447 447
         assert_non_null(ssl_ctx);
448 448
 
449
-        openvpn_snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
449
+        snprintf(select_string, sizeof(select_string), "THUMB:%s", c->hash);
450 450
         if (!SSL_CTX_use_CryptoAPI_certificate(ssl_ctx, select_string))
451 451
         {
452 452
             fail_msg("SSL_CTX_use_CryptoAPI_certificate failed: <%s>", c->friendly_name);
... ...
@@ -161,7 +161,7 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
161 161
     }
162 162
     else if (flags & GET_USER_PASS_PASSWORD_ONLY)
163 163
     {
164
-        openvpn_snprintf(up->password, sizeof(up->password), "%s", PIN);
164
+        snprintf(up->password, sizeof(up->password), "%s", PIN);
165 165
     }
166 166
     else
167 167
     {
... ...
@@ -204,8 +204,8 @@ init(void **state)
204 204
     {
205 205
         fail_msg("make tmpfile using template <%s> failed (error = %d)", softhsm2_conf_path, errno);
206 206
     }
207
-    openvpn_snprintf(config, sizeof(config), "directories.tokendir=%s/",
208
-                     softhsm2_tokens_path);
207
+    snprintf(config, sizeof(config), "directories.tokendir=%s/",
208
+             softhsm2_tokens_path);
209 209
     assert_int_equal(write(fd, config, strlen(config)), strlen(config));
210 210
     close(fd);
211 211