5104 Commits

Author SHA1 Message Date
icy17
d45dca4373 Fix potential Null pointer dereference in regress_thread.c 2024-04-15 10:16:26 +03:00
icy17
2bdf17370c Fix potential Null pointer dereference in regress_finalize.c 2024-04-15 10:08:00 +03:00
icy17
17796a2d8a Fix potential Null pointer dereference in regress_http.c 2024-04-15 10:06:42 +03:00
icy17
f9526e13ce Fix potential NULL pointer dereference in regress_bufferevent.c 2024-04-15 10:05:32 +03:00
icy17
fc48803db4
Fix potential Null pointer dereference in regress_zlib.c (#1597)
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2024-04-15 10:02:27 +03:00
emma-coronado
c6e8f17541 Edit logo path to match new website directory 2024-04-08 07:08:49 +02:00
Liu Dongmiao
39073df831 evutil: don't call memset before memcpy
In `evutil_parse_sockaddr_port`, it would `memset` the `out` to zero,
however, the `memset` is unnecessary before `memcpy`, and may cause
undefined behavior if the `outlen` is invalid.

This should close #1573.
2024-03-31 18:32:36 +02:00
neil
4fd07f0ee8
Upgrade vmactions to use linux runners (#1570)
Co-authored-by: neil <neilgit@neilpang.com>
2024-03-12 21:56:35 +01:00
Azat Khuzhin
539f73e319 Fix leak in evbuffer_add_file() on empty files
Found by oss-fuzz, after coverage had been improved in google/oss-fuzz#11257
v2: adjust test
v3: fix for windows (_get_osfhandle() crashes when called on closed fd)
v4: fix for EVENT__DISABLE_MM_REPLACEMENT
2024-03-12 09:29:47 +01:00
Azat Khuzhin
b9e1fe74e7 ci: disable netbsd and freebsd due to lack of runners
For example for openbsd-cmake-job (7.2, NONE)

    This request was automatically failed because there were no enabled runners online to process the request for more than 1 days.

And maybe this will fix the macos builds.
2024-03-11 21:00:18 +01:00
Andy Pan
0054b9aadb
Enable the full TCP KeepAlive mechanism on Windows (#1568)
#1532 implemented the full support of TCP Keep-Alives on UNIX-like OS's while leaving a `TODO` for Windows. This PR intends to resolve that `TODO`.

## References
 
- [SIO_KEEPALIVE_VALS Control Code](https://learn.microsoft.com/en-us/windows/win32/winsock/sio-keepalive-vals)
- [IPPROTO_TCP socket options](https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options)
- [TCP_KEEPINVTL and TCP_KEEPIDLE - Socket Keep Alives not working](https://cygwin.com/pipermail/cygwin/2020-June/245436.html)
- [Cygwin: tcp: Support TCP_KEEPIDLE, TCP_KEEPCNT, TCP_KEEPINTVL](https://sourceware.org/pipermail/cygwin-cvs/2020q3/014473.html)
- [Add cross-platform support for keep-alive socket options](https://github.com/dotnet/corefx/pull/29963/files)
2024-03-11 10:12:14 +01:00
tgolang
9c8860ec6c chore: remove repetitive words
Signed-off-by: tgolang <seekseat@aliyun.com>
2024-03-11 09:18:25 +01:00
Andy Pan
e66df92cfc
Accept SOCK_NONBLOCK/SOCK_CLOEXEC in type argument of socketpair (#1567)
Setting `SOCK_NONBLOCK` and `SOCK_CLOEXEC` in the `type` argument of `socketpair()` is widely supported across UNIX-like OS: Linux, *BSD, Solaris, etc., as is the `socket()`. This will conserve several extra system calls, we should use it where available.

### References

- [socketpair(2) on Linux](https://man7.org/linux/man-pages/man2/socketpair.2.html#HISTORY)
- [socketpair(2) on FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=socketpair&sektion=2#DESCRIPTION)
- [socketpair(2) on DragonFly](https://man.dragonflybsd.org/?command=socketpair&section=2)
- [socketpair(2) on NetBSD](https://man.netbsd.org/socketpair.2#DESCRIPTION)
- [socketpair(2) on OpenBSD](https://man.openbsd.org/socketpair.2)
- [socketpair(3C) on Solaris](https://docs.oracle.com/cd/E88353_01/html/E37843/socketpair-3c.html)

Changelog:
- Set SOCK_NONBLOCK and SOCK_CLOEXEC in the type argument of socketpair
- Avoid EPROTOTYPE on macOS and OpenBSD
- Eliminate the warnings about unused variables
- Add some comments
2024-03-07 09:19:11 +01:00
Azat Khuzhin
f2b3ce6b55
Merge pull request #1558 from azat/ratelimit-fixes
Fix few issues found by oss-fuzz in bufferevent ratelimits
2024-03-03 23:10:48 +01:00
Azat Khuzhin
e4b8732701 Fix integer-overflow in ev_token_bucket_cfg_new
Found by oss-fuzz, after coverage had been improved in https://github.com/google/oss-fuzz/pull/11257

v2: better check (found by CI for windows)
2024-03-03 16:25:08 +01:00
Azat Khuzhin
15e643d0ca Fix pread detection for cmake builds
Otherwise it will use lseek()+read() - suboptimal
2024-03-03 16:04:56 +01:00
Andy Pan
921097477e Simplify TCP_KEEPALIVE_ABORT_THRESHOLD settings on Solaris 2024-03-03 13:57:38 +01:00
Azat Khuzhin
c4fb0f7603 Fix divide-by-zero in ev_token_bucket_get_tick_
Found by oss-fuzz, after coverage had been improved in https://github.com/google/oss-fuzz/pull/11257
2024-02-20 08:58:04 +01:00
Azat Khuzhin
ec8d7a5a7b
ci: fix ABI check (#1510) 2024-02-20 08:54:14 +01:00
Pierce Lopez
7eddd5262a Patch abi-compliance-checker to avoid endless loop 2024-02-20 08:25:09 +01:00
Pierce Lopez
798547ac20 Force abi-check to use DWARF 3 2024-02-20 08:13:04 +01:00
Azat Khuzhin
e486962561 Fix abi_check.sh by excluding .abi-check from cp
cp: cannot copy a directory, './.abi-check', into itself, '/le/src/.abi-check/work/abi-check/src/libevent/current/.abi-check'
2024-02-20 08:13:04 +01:00
Azat Khuzhin
5bdfab7679 Debug abi check 2024-02-20 07:53:18 +01:00
Azat Khuzhin
f37c667cba Add ABI check without deploy for PRs 2024-02-20 07:53:18 +01:00
Azat Khuzhin
551df0b2f1 ci: try to fix ABI check by using newer version of ubuntu
Looks like after upgrading ubuntu from 18.04 (that has 1.9 version of
lvc abi tools) to 20.04 (that has 1.11) the abi-check started to
timeout (works longer then 6 hours, while usually few minutes, and
sometimes even faster was enough).

Unlikely upgrading ubuntu will help, since 22.04 and 20.04 has the same
version, but still, let's try.

Refs: #1463
2024-02-20 07:50:35 +01:00
Azat Khuzhin
0dbd3eb3c9 tests: add test for EV_SIGNAL with timeout
Refs: https://github.com/libevent/libevent-book/issues/12
2024-02-19 22:07:32 +01:00
Azat Khuzhin
5cec3417bf
Make Infer static analyzer happy (#1554) 2024-02-19 08:21:11 +01:00
Ramon Ortega de Voor
ed35b30feb Fix two compiler errors for unused variable and undefined function
In buffer.c a variable "flags" and a label "done" are defined but
never used if "EVENT__HAVEMMAP" is not defined.

The code does not work on platforms which do not provide
the function `socketpair()`. Introduce EVENT__HAVE_SOCKETPAIR flag
which determines if `socketpair()` or `evutil_ersatz_socketpair()`
is used.
2024-02-19 08:19:24 +01:00
Azat Khuzhin
95ed33e37a
Follow up for HTTP chunk size check (#1552) 2024-02-18 22:08:54 +01:00
Azat Khuzhin
f9939490eb Fix leak in evconnlistener_new_async()
Fixes: https://github.com/libevent/libevent/issues/414
2024-02-18 22:07:22 +01:00
Azat Khuzhin
317911a1a0 Fix util/monotonic_prc_fallback under FreeBSD
Looks like there was garbage, since evutil_configure_monotonic_time_()
does not reset evutil_monotonic_timer structure, while in case of
fallback it uses two fields from it:
- last_time
- adjust_monotonic_clock

Fixes: https://github.com/libevent/libevent/issues/1495
2024-02-18 20:40:53 +01:00
Azat Khuzhin
3cf996f0ed evutil: add a comment why no NULL check in evutil_inet_pton_scope() 2024-02-18 19:53:58 +01:00
Azat Khuzhin
5412b2c30d bufferevent_ssl: fix freeing ctx in case of error in bufferevent_ssl_new_impl 2024-02-18 19:51:21 +01:00
Azat Khuzhin
c9793baa87 bufferevent_ssl: proper NULL checks 2024-02-18 19:49:44 +01:00
Azat Khuzhin
6e4ea6c3f1 evthread: fix NULL dereference in evthread_setup_global_lock_() 2024-02-18 19:49:44 +01:00
Azat Khuzhin
2f27523e44 bufferevent_ssl: do not return NULL from upcast
/src/le/libevent/bufferevent_ssl.c:863: error: Null Dereference
      pointer `bev_ssl` last assigned on line 855 could be null and is dereferenced at line 863, column 6.
      861.          r2 = start_writing(bev_ssl);
      862.
      863.  if (bev_ssl->underlying) {
                ^
      864.          if (events & EV_READ)
      865.                  BEV_RESET_GENERIC_READ_TIMEOUT(bev);
2024-02-18 19:49:44 +01:00
Azat Khuzhin
5303493670 bufferevent_filter: do not allow upcast() to return NULL (fixes infer warning)
/src/le/libevent/bufferevent_filter.c:234: error: Null Dereference
      pointer `bevf` last assigned on line 231 could be null and is dereferenced at line 234, column 6.
      232.  EVUTIL_ASSERT(bevf);
      233.
      234.  if (bevf->bev.options & BEV_OPT_CLOSE_ON_FREE) {
                ^
      235.          /* Yes, there is also a decref in bufferevent_decref_.
      236.           * That decref corresponds to the incref when we set
2024-02-18 19:49:44 +01:00
Azat Khuzhin
d9b5fe318a evrpc: proper NULL checks (API function return value added)
Note, that in order to do this evrpc_hook_add_meta() should have return
value, so this is a minor ABI change, which should not affect C ABI, but
still worth to mention.

Anyway this will be done in 2.2 release and unlikely RPC subsystem is
popular.
2024-02-18 19:48:55 +01:00
Azat Khuzhin
05ed7c8c7e bufferevent_pair: fix infer warnings due to upcast() return NULL
The only user that is care about this is bufferevent_pair_get_partner(),
so let's move the check there.
2024-02-18 19:48:22 +01:00
Azat Khuzhin
8feed7f165
http: forbid chunks size with 0X prefix
Co-authored-by: Ben Kallus <49924171+kenballus@users.noreply.github.com>
2024-02-18 19:26:47 +01:00
Azat Khuzhin
87cdcc1868 http: change error for corrupted requests to 400 Bad Request
Previously it was 413 Request Entity Too Large, which was odd.
2024-02-18 17:02:45 +01:00
Azat Khuzhin
f1632e5909 http: check first byte of the chunk for 0x as well 2024-02-18 17:02:45 +01:00
Azat Khuzhin
e60d039ddf tests: add a test for malformed chunks
v2: fix test for win32 (and it more correct in general)
2024-02-18 17:02:32 +01:00
Ben Kallus
92ea8476b4
Forbid 0x/+/-/whitespace prefixes on HTTP chunk sizes (#1542)
Currently, libevent's HTTP parser accepts and ignores 0x, +, and whitespace prefixes on chunk sizes. It also ignores - prefixes on chunk sizes of 0. This patch fixes that.

There is a potential danger in the current behavior, which is that there exist HTTP implementations that interpret chunk sizes as their longest valid prefix. For those implementations, 0xa (for example) is equivalent to 0, and this may present a request smuggling risk when those implementations are used in conjunction with libevent. However, as far I'm aware, there is no HTTP proxy that both interprets 0xa as 0 and forwards it verbatim, so I think this is a low-risk bug that is acceptable to report in public.
2024-02-18 14:56:46 +01:00
Azat Khuzhin
da3c7b5027 Update link to the github package registry usage from github actions
Ugh, old link even don't have any redirect, what is a pitty.

[skip ci]
2024-02-18 12:45:21 +01:00
kurtliu
7870e85ecb install DESTINATION use CMAKE_INSTALL_<dir> 2024-01-24 10:20:47 +01:00
kurtlau
b698e6c4b0
Make MbedTLS and OpenSSL dependencies configurable (#1544)
As acfac7a#r124469888 mentioned, LibeventConfig.cmake is looking for MBedTLS package, even if libevent is not configured to use MBedTLS.

This PR makes MbedTLS and OpenSSL dependencies configurable.

Fixes: #1543
2024-01-22 21:29:04 +01:00
Ben Kallus
665d79f176
Fix integer overflow in HTTP version (#1541)
Currently, when libevent parses requests with version `HTTP/4294967295.255`, you end up with `req->major == req->minor == (char)-1`. (At least on linux-gnu-x86_64, where `char` is signed.)

This is sort of weird.

This patch changes the version parser to match the grammar in RFCs 7230 and 9112. (i.e. `HTTP/[0-9].[0-9]`)

EDIT: Technically, a little stronger than the RFC requires, since this patch continues to block major versions greater than 1, which was already what libevent was doing.
2024-01-19 00:42:52 +03:00
Andy Pan
55899c2fcb Use read/write instead of readv/writev for single buffer
The `readv`/`writev` functions are designed for scattered I/O optimally,
their logic in the kernel is more sophisticated, compared to read/write,
which includes extra on-stack `iovec` in the kernel space, importing `iovec`
array from user space to kernel space, reading/writing with `iov_iter`, etc.
As a result, using `readv`/`writev` on single-segment `iovec` will fall into
the special branch in the kernel where it is imported as `ITER_UBUF` differed
from `ITER_IOVEC` for multiple-segments `iovec`.

Thus, it is just not worth calling `readv`/`writev` for single-segment `iovec`,
we should use `read`/`write` instead, to save it from going through the
sophisticated yet unnecessary kernel code path, circumvent a waste of
kernel on-stack memory, copying `iovec` between user space and kernel space, etc.
2024-01-19 00:41:03 +03:00
Andy Pan
3f508af6e2 Ignore the project files from IDE or editors
I sometimes browse and edit C/C++ code with VSCode,
and it would generate some project files in .vscode
which could easily be added and even pushed to a git repo by accident.

It's sort of annoying for programmers who work with VS/VSCode,
IntelliJ/Clion, or other widely-used IDE or editors to prevent
themself from using git command like `git add .` in lib event project.

Therefore, I propose leaving the project files generated by VS/VSCode
and IntelliJ/Clion untracked for libevent project. Hopefully, this can be accepted.
2024-01-15 10:50:48 +03:00