This function was only called in string format functions, which already
copy the contents, so all this ever did was adding redundant malloc() and
free() calls.
Also, this wasn't as thread-safe as it claims: another thread could still
change the string value between the strerror() and buf_printf() calls. So,
instead of a not needed false sense of thread-safeness, just be honest and
use strerror() directly.
(I think we should find a better place for everything currently in misc.c,
and get rid of it all together. In this case, the better place is
/dev/null. This patch is part of that effort.)
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1500550740-24773-1-git-send-email-steffan.karger@fox-it.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15105.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -662,7 +662,7 @@ AC_FUNC_FORK |
662 | 662 |
|
663 | 663 |
AC_CHECK_FUNCS([ \ |
664 | 664 |
daemon chroot getpwnam setuid nice system getpid dup dup2 \ |
665 |
- getpass strerror syslog openlog mlockall getgrnam setgid \ |
|
665 |
+ getpass syslog openlog mlockall getgrnam setgid \ |
|
666 | 666 |
setgroups stat flock readv writev time gettimeofday \ |
667 | 667 |
ctime memset vsnprintf strdup \ |
668 | 668 |
setsid chdir putenv getpeername unlink \ |
... | ... |
@@ -267,7 +267,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist) |
267 | 267 |
if ((flags & M_ERRNO) && e) |
268 | 268 |
{ |
269 | 269 |
openvpn_snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=%d)", |
270 |
- m1, strerror_ts(e, &gc), e); |
|
270 |
+ m1, strerror(e), e); |
|
271 | 271 |
SWAP; |
272 | 272 |
} |
273 | 273 |
|
... | ... |
@@ -693,20 +693,15 @@ x_check_status(int status, |
693 | 693 |
{ |
694 | 694 |
if (extended_msg) |
695 | 695 |
{ |
696 |
- msg(x_cs_info_level, "%s %s [%s]: %s (code=%d)", |
|
697 |
- description, |
|
696 |
+ msg(x_cs_info_level, "%s %s [%s]: %s (code=%d)", description, |
|
698 | 697 |
sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "", |
699 |
- extended_msg, |
|
700 |
- strerror_ts(my_errno, &gc), |
|
701 |
- my_errno); |
|
698 |
+ extended_msg, strerror(my_errno), my_errno); |
|
702 | 699 |
} |
703 | 700 |
else |
704 | 701 |
{ |
705 |
- msg(x_cs_info_level, "%s %s: %s (code=%d)", |
|
706 |
- description, |
|
702 |
+ msg(x_cs_info_level, "%s %s: %s (code=%d)", description, |
|
707 | 703 |
sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "", |
708 |
- strerror_ts(my_errno, &gc), |
|
709 |
- my_errno); |
|
704 |
+ strerror(my_errno), my_errno); |
|
710 | 705 |
} |
711 | 706 |
|
712 | 707 |
if (x_cs_err_delay_ms) |
... | ... |
@@ -2006,9 +2006,8 @@ man_io_error(struct management *man, const char *prefix) |
2006 | 2006 |
if (!ignore_sys_error(err)) |
2007 | 2007 |
{ |
2008 | 2008 |
struct gc_arena gc = gc_new(); |
2009 |
- msg(D_MANAGEMENT, "MANAGEMENT: TCP %s error: %s", |
|
2010 |
- prefix, |
|
2011 |
- strerror_ts(err, &gc)); |
|
2009 |
+ msg(D_MANAGEMENT, "MANAGEMENT: TCP %s error: %s", prefix, |
|
2010 |
+ strerror(err)); |
|
2012 | 2011 |
gc_free(&gc); |
2013 | 2012 |
return true; |
2014 | 2013 |
} |
... | ... |
@@ -444,21 +444,6 @@ init_random_seed(void) |
444 | 444 |
} |
445 | 445 |
} |
446 | 446 |
|
447 |
-/* thread-safe strerror */ |
|
448 |
- |
|
449 |
-const char * |
|
450 |
-strerror_ts(int errnum, struct gc_arena *gc) |
|
451 |
-{ |
|
452 |
-#ifdef HAVE_STRERROR |
|
453 |
- struct buffer out = alloc_buf_gc(256, gc); |
|
454 |
- |
|
455 |
- buf_printf(&out, "%s", openvpn_strerror(errnum, gc)); |
|
456 |
- return BSTR(&out); |
|
457 |
-#else |
|
458 |
- return "[error string unavailable]"; |
|
459 |
-#endif |
|
460 |
-} |
|
461 |
- |
|
462 | 447 |
/* |
463 | 448 |
* Set environmental variable (int or string). |
464 | 449 |
* |
... | ... |
@@ -95,12 +95,6 @@ openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigne |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
|
98 |
-#ifdef HAVE_STRERROR |
|
99 |
-/* a thread-safe version of strerror */ |
|
100 |
-const char *strerror_ts(int errnum, struct gc_arena *gc); |
|
101 |
- |
|
102 |
-#endif |
|
103 |
- |
|
104 | 98 |
/* Set standard file descriptors to /dev/null */ |
105 | 99 |
void set_std_files_to_null(bool stdin_only); |
106 | 100 |
|
... | ... |
@@ -1473,10 +1473,8 @@ socket_connect(socket_descriptor_t *sd, |
1473 | 1473 |
if (status) |
1474 | 1474 |
{ |
1475 | 1475 |
|
1476 |
- msg(D_LINK_ERRORS, |
|
1477 |
- "TCP: connect to %s failed: %s", |
|
1478 |
- print_sockaddr(dest, &gc), |
|
1479 |
- strerror_ts(status, &gc)); |
|
1476 |
+ msg(D_LINK_ERRORS, "TCP: connect to %s failed: %s", |
|
1477 |
+ print_sockaddr(dest, &gc), strerror(status)); |
|
1480 | 1478 |
|
1481 | 1479 |
openvpn_close_socket(*sd); |
1482 | 1480 |
*sd = SOCKET_UNDEFINED; |