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
Azat Khuzhin [Sun, 10 Jul 2022 13:49:53 +0000 (16:49 +0300)]
Rework CI to keep everything in one workflow (by using reusable workflow)
Right now because we have separate workflows there is no one page with
all the jobs, instead we have separate page for each workflow (linux,
windows, ...)
This is pretty inconvenient, so let's make it cleaner, and now we will
have only two:
Azat Khuzhin [Sun, 10 Jul 2022 10:55:32 +0000 (13:55 +0300)]
Initial OpenSSL 3.0 support (#1288)
* openssl-3:
ci: use ubuntu 22.04 with OpenSSl 3.0 instead of building OpenSSL from sources
ci: set LD_LIBRARY_PATH for openssl 3.0 build
test: suppress warning for already defined SSL_get_peer_certificate
autotools: print $OPENSSL_LIBS/$OPENSSL_INCS
Suppress -Wunused-value for BIO_set_close()
Use OPENSSL_VERSION_NUMBER over OPENSSL_VERSION_MAJOR (for compatibility)
Attempt to add OpenSSL 3 to the Linux build matrix
Initial OpenSSL 3.0 support
Azat Khuzhin [Sun, 10 Jul 2022 09:24:42 +0000 (12:24 +0300)]
ci: set LD_LIBRARY_PATH for openssl 3.0 build
Fixes:
/home/runner/work/libevent/libevent/build/test/.libs/regress: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
Azat Khuzhin [Sun, 10 Jul 2022 06:59:14 +0000 (09:59 +0300)]
test: suppress warning for already defined SSL_get_peer_certificate
build report:
[1/2] Building C object CMakeFiles/regress.dir/test/regress_mbedtls.c.o
/src/le/libevent/test/regress_mbedtls.c:50: warning: "SSL_get_peer_certificate" redefined
50 | #define SSL_get_peer_certificate mbedtls_ssl_get_peer_cert
|
In file included from /src/le/libevent/test/regress.h:139,
from /src/le/libevent/test/regress_mbedtls.c:35:
/src/oss/openssl/include/openssl/ssl.h:1799: note: this is the location of the previous definition
1799 | # define SSL_get_peer_certificate SSL_get1_peer_certificate
|
[2/2] Linking C executable bin/regress
William Marlow [Sat, 18 Jun 2022 20:43:31 +0000 (21:43 +0100)]
Initial OpenSSL 3.0 support
* Don't use deprecated functions when building against OpenSSL 3.0.
* Recognise that OpenSSL 3.0 can signal a dirty shutdown as a protocol.
error in addition to the expected IO error produced by OpenSSL 1.1.1
* Update regress_mbedtls.c for compatibility with OpenSSL 3
Azat Khuzhin [Sat, 9 Jul 2022 20:22:00 +0000 (23:22 +0300)]
Merge branch 'mbedtls-3'
* mbedtls-3:
sample/ssl-client-mbedtls.c: fix for MbedTLS 3
sample/ssl-client-mbedtls.c: break the loop on EOF
sample/ssl-client-mbedtls.c: fix printing response in readcb
Initial Mbed-TLS 3 support to get the GitHub Actions working again
Support build dir of the MbedTLS
Azat Khuzhin [Sat, 9 Jul 2022 18:14:16 +0000 (21:14 +0300)]
Merge branch 'fix-brew-autodetection'
* fix-brew-autodetection:
ci: fix cmake build w/o OPENSSL_ROOT_DIR
ci: remove separate build for BREW_AUTODETECT_OPENSSL (use it by default)
autotools: fix autodetection of openssl location via brew
Azat Khuzhin [Sat, 9 Jul 2022 17:28:18 +0000 (20:28 +0300)]
configure: fix AC_CHECK_FUNCS should use literals
Error
configure.ac:291: warning: AC_CHECK_FUNCS(getnameinfo
): you should use literals
../autoconf-2.71/lib/autoconf/functions.m4:117: AC_CHECK_FUNCS is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
configure.ac:291: the top level
configure.ac:291: warning: AC_CHECK_FUNCS(getprotobynumber
): you should use literals
../autoconf-2.71/lib/autoconf/functions.m4:117: AC_CHECK_FUNCS is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
configure.ac:291: the top level
configure.ac:291: warning: AC_CHECK_FUNCS(getservbyname
): you should use literals
../autoconf-2.71/lib/autoconf/functions.m4:117: AC_CHECK_FUNCS is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
configure.ac:291: the top level
configure.ac:291: warning: AC_CHECK_FUNCS(inet_ntop
): you should use literals
../autoconf-2.71/lib/autoconf/functions.m4:117: AC_CHECK_FUNCS is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
configure.ac:291: the top level
configure.ac:291: warning: AC_CHECK_FUNCS(inet_pton
): you should use literals
../autoconf-2.71/lib/autoconf/functions.m4:117: AC_CHECK_FUNCS is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
../autoconf-2.71/lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
configure.ac:291: the top level
listener: Preserve last error in evconnlistener_new_bind() before close
In function evconnlistener_new_bind() after go to "err:", The
evutil_closesocket() would clear the error code( I found this under
Windows ). User can not use EVUTIL_SOCKET_ERROR() to get the
evconnlistener_new_bind()'s failing error.
I add a err_code variable to store and restore the last error code.
Azat Khuzhin [Sat, 9 Jul 2022 15:12:07 +0000 (18:12 +0300)]
Merge branch 'Werror'
* Werror:
test: ignore -Walloc-size-larger-than error for calloc() returns ENOMEM
Fix EVBASE_ACQUIRE_LOCK/EVBASE_RELEASE_LOCK for EVENT__DISABLE_THREAD_SUPPORT
http: suppress "flags may be used uninitialized in this function" error
Detech -Wno-unused-functions for GCC too
cmake: add compiler version to the status message
Fix BEV_LOCK/BEV_UNLOCK macros for EVENT__DISABLE_THREAD_SUPPORT
Run builds with -Werror on CI for linux
Fix -Werror for autotools
Add -Wundef for cmake and fix EVENT__SIZEOF_TIME_T usage
Azat Khuzhin [Sat, 9 Jul 2022 14:14:12 +0000 (17:14 +0300)]
test: ignore -Walloc-size-larger-than error for calloc() returns ENOMEM
Compiler report:
/home/runner/work/libevent/libevent/test/regress_util.c: In function ‘test_event_calloc’:
/home/runner/work/libevent/libevent/test/regress_util.c:1318:4: error: argument 2 value ‘9223372036854775815’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
p = mm_calloc(EV_SIZE_MAX/2, EV_SIZE_MAX/2 + 8);
In file included from /home/runner/work/libevent/libevent/test/../util-internal.h:37:0,
from /home/runner/work/libevent/libevent/test/regress_util.c:30:
/usr/include/stdlib.h:541:14: note: in a call to allocation function ‘calloc’ declared here
extern void *calloc (size_t __nmemb, size_t __size)
Azat Khuzhin [Sat, 9 Jul 2022 14:17:38 +0000 (17:17 +0300)]
http: suppress "flags may be used uninitialized in this function" error
Some GCC reports [1]:
/home/runner/work/libevent/libevent/http.c: In function ‘evhttp_make_header’:
/home/runner/work/libevent/libevent/http.c:503:14: error: ‘flags’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
ev_uint16_t flags;
^~~~~
/home/runner/work/libevent/libevent/http.c: In function ‘evhttp_get_body’:
/home/runner/work/libevent/libevent/http.c:2354:14: error: ‘flags’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
ev_uint16_t flags;
^~~~~
[1]: https://github.com/libevent/libevent/runs/7263518338?check_suite_focus=true#logs
Azat Khuzhin [Sat, 9 Jul 2022 14:08:21 +0000 (17:08 +0300)]
Detech -Wno-unused-functions for GCC too
Otherwise build fails [1]:
/home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/minheap-internal.h:64:6: error: ‘min_heap_ctor_’ defined but not used [-Werror=unused-function]
void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; }
^~~~~~~~~~~~~~
In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:91:0:
/home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/bufferevent-internal.h:414:1: error: ‘bufferevent_trigger_nolock_’ defined but not used [-Werror=unused-function]
bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:89:0:
/home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/evthread-internal.h:140:1: error: ‘EVLOCK_TRY_LOCK_’ defined but not used [-Werror=unused-function]
EVLOCK_TRY_LOCK_(void *lock)