Cœur [Thu, 2 Mar 2023 04:41:11 +0000 (12:41 +0800)]
Optimize arc4random_uniform() (by syncing with OpenBSD implementation)
1. In d4de062, in Feb 2010, libevent adopted OpenBSD implementation of
arc4random_uniform.
2. In
https://github.com/openbsd/src/commit/728918cba93e0418bea2a73c9784f6b80c2a9dbd,
in Jun 2012, OpenBSD improved their implementation to be faster, by
changing arc4random_uniform() to calculate ``2**32 % upper_bound'' as
``-upper_bound % upper_bound''.
Alternatively we can simply remove arc4random_uniform() since it is not
used by libevent anyway, but let's just sync the header for now.
Azat Khuzhin [Sun, 12 Feb 2023 14:24:06 +0000 (15:24 +0100)]
Remove extra builds for autotools on CI
We have almost the same matrix for cmake and autotools, but autotools is
considered to be deprecated from now on, plus our CI takes too much
time, especially non-linux, since we are using public infrastucture.
Edoardo Lolletti [Sun, 12 Feb 2023 15:19:35 +0000 (16:19 +0100)]
Fix compilation on non recent windows SDKs (#1399)
In commit f8bb9d8 the header stringapiset.h was included, very likely because the user who made the change saw that the funciton WideCharToMultiByte is "declared" in there.
That header tho is a recent addition to the windows headers added in the last years in an attempt from microsoft to split the windows.h header in multiple files, so the inclusion fails when the library is not built with the latest visual studio using the latest windows 10 sdk.
That inclusion can be safely removed as in any case the function WideCharToMultiByte was already included by the windows.h header that is included few lines below.
Azat Khuzhin [Sun, 12 Feb 2023 07:50:05 +0000 (08:50 +0100)]
Merge branch 'tests-fixes'
* tests-fixes:
Add more ignore rules
test: fix debug locks in case new lock gots old address
test: suppress logs from the tests that produce them under normal circumstances
test: fix TT_* flags values
Suppress data race for test_ok variable
Suppress data race for event_debug_created_threadable_ctx_ variable
Libevent introduced the LEV_OPT_BIND_IPV6ONLY to pass to evconnlistener_new_bind to make it automatically set the underlying socket as accepting ipv6 requests. This works fine on posix compliant platforms as by the standard every new AF_INET6 socket is created as both supporting ipv6 and ipv4 connections. But on windows the default is the opposite, with the flag IPV6_V6ONLY being always enabled by default.
This makes creating a listener to supports both protocols a bit more tricky as winsock doesn't allow changing this flag after evconnlistener_new_bind does all the initial setup because as stated in the docs, you can't change it after the sonnect connected, so one would have to manually create the socket beforehand and set the flag and then call evconnlistener_new with the socket itself.
It would be nice to have libevent keep a consistent behaviour across the platforms in this scenario, maybe or by making it always set IPV6_V6ONLY to false unless LEV_OPT_BIND_IPV6ONLY is passed, in which case it's set to true, or add another flag to forcefully set it to false and keep the system dependent behaviour as default.
So this patch add new option for libevent listeners to bind to both - LEV_OPT_BIND_IPV4_AND_IPV6
Azat Khuzhin [Fri, 27 Jan 2023 07:57:33 +0000 (08:57 +0100)]
Fixes some new warnings under clang-15
- -Wdeprecated-non-prototype
/src/le/libevent/strlcpy.c:48:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
event_strlcpy_(dst, src, siz)
- -Wstrict-prototypes
/src/le/libevent/evthread.c:82:70: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
struct evthread_condition_callbacks *evthread_get_condition_callbacks()
- -Wunused-but-set-variable
/src/le/libevent/test/regress_buffer.c:130:6: warning: variable 'n' set but not used [-Wunused-but-set-variable]
int n = 0;
^
Azat Khuzhin [Fri, 27 Jan 2023 07:51:56 +0000 (08:51 +0100)]
Allow evdns_base_new to succeed with no nameservers configured (#1389)
* evdns-no-ns:
Allow evdns_base_new to succeed with no nameservers configured
Replace magic numbers with consts for evdns_base_resolv_conf_parse() errors
Daniel Kempenich [Fri, 27 Jan 2023 07:44:41 +0000 (08:44 +0100)]
Allow evdns_base_new to succeed with no nameservers configured
If resolv.conf has no nameservers, evdns_base_new can still succeed with
the default of using the name server from localhost matching the man
page documentation for resolv.conf.
liaotonglang [Tue, 10 Jan 2023 03:20:24 +0000 (11:20 +0800)]
Fix ignoring return value of arc4random() warning (with _FORTIFY_SOURCE defined)
arc4random() defines with __wur (warn-unused-return) macro in glibc, but
the problem pops up only for gentoo, since only it really define __wur
to __attribute__ ((__warn_unused_result__)), because it defines
_FORTIFY_SOURCE unconditionally [1].
Srivatsan Iyer [Tue, 15 Nov 2022 07:08:41 +0000 (12:38 +0530)]
Exclude arc4random_buf implementation if it's already present in the platform (#1375)
This patch excludes definition of arc4random_buf on systems where it is already present. When the symbol is found, the macro EVENT__HAVE_ARC4RANDOM_BUF is set via CMake's configure_file(..).
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
mkm [Tue, 1 Nov 2022 13:26:11 +0000 (14:26 +0100)]
evdns: integrate deferred_response_callback into evdns_request
the allocation of the struct deferred_reply_callback can fail. If that
happens a program waiting for a callback never gets a callback. The
program would asume that it either gets an error or a callback when e.g.
calling evdns_base_resolve_ipv6.
I did an analysis of the evdns.c code and concluded that struct
evdns_request would live until the callback is executed. Based on that
conclusion I removed the struct deferred_reply_callback and moved the
neccessary fields for data which should be copied from struct request
into struct evdns_request.
The fields evdns_callback_type user_callback and void *user_pointer are
moved into struct evdns_request as it is a more natural place for them
to live than struct request.
Dmitry Antipov [Tue, 25 Oct 2022 08:30:34 +0000 (11:30 +0300)]
signal: new signal handling backend based on signalfd
Linux-specific signal handling backend based on signalfd(2)
system call, and public function event_base_get_signal_method()
to obtain an underlying kernel signal handling mechanism.
Azat Khuzhin [Sat, 12 Nov 2022 17:56:25 +0000 (18:56 +0100)]
Ignore unknown pragmas
Since new compilers has new checks (like -Wdangling-pointer), and so to
avoid extra checks in cmake/autotools, simply suppress if the pragma is
unknown.
Azat Khuzhin [Sat, 12 Nov 2022 17:06:09 +0000 (18:06 +0100)]
Suppress -Wdangling-pointer in event_signal_closure()
gcc 12 complains:
[34/46] Building C object CMakeFiles/event_static.dir/event.c.o
/src/le/libevent/event.c: In function ‘event_signal_closure’:
/src/le/libevent/event.c:1384:32: warning: storing the address of local variable ‘ncalls’ in ‘*ev.ev_.ev_signal.ev_pncalls’ [-Wdangling-pointer=]
1384 | ev->ev_pncalls = &ncalls;
| ~~~~~~~~~~~~~~~^~~~~~~~~
/src/le/libevent/event.c:1378:15: note: ‘ncalls’ declared here
1378 | short ncalls;
| ^~~~~~
/src/le/libevent/event.c:1378:15: note: ‘ev’ declared here
Azat Khuzhin [Sat, 12 Nov 2022 16:56:51 +0000 (17:56 +0100)]
sha1: ignore -Wstringop-overread warning
Fixes the following:
[4/38] Building C object CMakeFiles/event_shared.dir/sha1.c.o
In function ‘SHA1Update’,
inlined from ‘SHA1Final’ at /src/le/libevent/sha1.c:274:5,
inlined from ‘builtin_SHA1’ at /src/le/libevent/sha1.c:292:5:
/src/le/libevent/sha1.c:228:13: warning: ‘SHA1Transform’ reading 64 bytes from a region of size 7 [-Wstringop-overread]
228 | SHA1Transform(context->state, *(const unsigned char (*)[64])&data[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/le/libevent/sha1.c:228:13: note: referencing argument 2 of type ‘const unsigned char[64]’
/src/le/libevent/sha1.c: In function ‘builtin_SHA1’:
/src/le/libevent/sha1.c:80:13: note: in a call to function ‘SHA1Transform’
80 | static void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
| ^~~~~~~~~~~~~
Leon George [Sun, 23 Oct 2022 11:47:23 +0000 (13:47 +0200)]
ws: fix compile error on centos 7 - very old compiler (#1359)
* http: fix typo
* ws: fix comile error
On CentOS:
CC ws.lo
ws.c: In function 'get_ws_frame':
ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode
for (int i = 0; i < payload_len; i++) {
^
ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code
Azat Khuzhin [Sat, 22 Oct 2022 20:23:52 +0000 (22:23 +0200)]
Fix data-race in ws code (#1360)
@widgetii:
"
=================================================================
==985==ERROR: AddressSanitizer: heap-use-after-free on address 0xb24323e5 at pc 0xb6a06f1c bp 0x9fffc694 sp 0x9fffc260
WRITE of size 2 at 0xb24323e5 thread T22
#0 0xb6a06f1b in __interceptor_memcpy.part.43 (/usr/lib/libasan.so.5+0x41f1b)
0xb24323e5 is located 229 bytes inside of 512-byte region [0xb2432300,0xb2432500)
freed by thread T0 (app) here:
#0 0xb6a849df in free (/usr/lib/libasan.so.5+0xbf9df)
#1 0xb64b6e07 in evbuffer_drain (/usr/lib/libevent_core-2.2.so.1+0x9e07)
previously allocated by thread T22 here:
#0 0xb6a84d17 in __interceptor_malloc (/usr/lib/libasan.so.5+0xbfd17)
#1 0xb64b3d1b (/usr/lib/libevent_core-2.2.so.1+0x6d1b)
#2 0x61223 in onIceCandidateHandler /home/dima/git/app/src/webrtc/local.c:116
#3 0x19296f in onNewIceLocalCandidate /home/dima/git/webrtc-c/src/source/PeerConnection/PeerConnection.c:471
"
* upstream/pr/1360:
Remove bad copy-paste
Add locks for server WS, fixes #1357
Azat Khuzhin [Sat, 8 Oct 2022 16:26:24 +0000 (19:26 +0300)]
Use heap-bases contexts for MbedTLS handles (#1355)
@widgetii:
"Recently after studying [https-client.c code](https://github.com/libevent/libevent/blob/master/sample/https-client.c#L532) I found that I cannot use MbedTLS with `bufferevent_mbedtls_socket_new` same way as for OpenSSL in other than hello-world code. In mentioned sample code, ssl context is created by `SSL_new()` (as heap-based pointer), but for MbedTLS stack value is used. The issue is in different semantics because OpenSSL is responsible for memory allocation and release for its context, but for MbedTLS it turns out user should do the same manually.
I expect that in both cases, setting option `BEV_OPT_CLOSE_ON_FREE` will free all linked resources, but in case of MbedTLS I have memory leak after connection is closed.
My proposal is:
1. Provide new `mbedtls_ssl_new` helper-function for end-user that do the same job as `SSL_new()` and use it and example in sample:
Azat Khuzhin [Wed, 14 Sep 2022 20:14:28 +0000 (22:14 +0200)]
ci: disable freebsd 13.0 builds (due to issues in the image)
Before it fails with:
exec ssh: pkg install -y mbedtls cmake python3
/bin/bash /Users/runner/work/_actions/vmactions/freebsd-vm/v0/run.sh execSSH
Config file: freebsd-13.0.conf
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
Installing pkg-1.18.3...
Newer FreeBSD version for package pkg:
To ignore this error set IGNORE_OSVERSION=yes
- package: 1301000
- running kernel: 1300139
Ignore the mismatch and continue? [y/N]:
Failed to install the following 1 package(s): /tmp//pkg.txz.18yvwm
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Error: The process '/bin/bash' failed with exit code 1
And now with:
ld-elf.so.1: /lib/libc.so.7: version FBSD_1.7 required by /usr/local/lib/libpython3.9.so.1.0 not found
Commenting for now, anyway we do not need such huge CI matrix, because
we have only public workers, and they are pretty busy.
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.
Implementation was inspired by modified Libevent source code in ipush project
[1].
Azat Khuzhin [Sat, 13 Aug 2022 22:46:48 +0000 (00:46 +0200)]
Merge pull request #1315 from yogo1212/http_per_socket_bebcb
In it's current form, libevent requires multiple struct evhttp objects to be created in order to enable listening on sockets with more than one type of encryption.
This change allows specifying per-socket how the associated bufferevents should be created.
Thus, it becomes possible to have multiple listening sockets with different encryption parameters using only one evttp.
Borys Smejda [Sat, 13 Aug 2022 17:10:10 +0000 (19:10 +0200)]
Fixed CMake configuration failure (libevent#1321)
Deleted usage of CMake feature 'file(REAL_PATH'
which is available from version 3.19
with an old 'get_filename_component' so that
older version of CMake can still be used
to configure the project.
Dmitry Ilyin [Sun, 7 Aug 2022 10:51:48 +0000 (13:51 +0300)]
Add check of mmap64 function and use it when available rather that mmap
There can be issues on 32-bit architectures to mmap 2+GiB file, and to
make this portable between different version of glibc, mmap64 was
prefered over _FILE_OFFSET_BITS