summaryrefslogtreecommitdiff
path: root/evutil.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix compilation on non recent windows SDKs (#1399)Edoardo Lolletti2023-02-121-1/+0
| | | | | 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.
* Add LEV_OPT_BIND_IPV4_AND_IPV6 flag (#1400)Edoardo Lolletti2023-02-041-0/+11
| | | | | | | | | 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
* Fix syntax error (#1369)OgreTransporter2022-11-041-1/+1
|
* fixed missing check for null after strdup in evutil_inet_pton_scope (#1366)Michael Madsen2022-11-041-1/+3
|
* Fix socketpair failure when temporary directory has non-latin characterzhenhaonong2022-09-261-13/+20
|
* evutil: Fix evutil_freeaddrinfoTomas Gonzalez2021-11-041-4/+35
| | | | | | | | | | | | | | | During testing on win32, util/getaddrinfo failed with NULL hint info r = evutil_getaddrinfo("www.google.com", NULL, NULL, &ai); throwing a critical heap exception when evutil_freeaddrinfo is called. This is because of improper use of freeaddrinfo when nodes within the ai structure are allocated using mm_malloc or mm_calloc (EVUTIL_AI_LIBEVENT_ALLOCATED) This adds the flag in apply_socktype_protocol_hack and walks the linked list in evutil_freeaddrinfo removing linked list nodes that are custom allocated before calling freeaddrinfo.
* Fix O_RDONLY (_O_RDONLY) under mingwAzat Khuzhin2021-04-271-0/+4
| | | | | | | | O_RDONLY is defined only if [1]: !defined(NO_OLDNAMES) || defined(_POSIX) [1]: https://github.com/Alexpux/mingw-w64/blob/d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-headers/crt/fcntl.h#L35
* Change log message in evutil_make_socket_nonblocking in win32guoxiang19962020-10-101-1/+1
| | | Co-authored-by: guoxiang2 <guoxiang2@yy.com>
* windows socketpair tmpfile: use random prefixPierce Lopez2020-07-261-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | fixes #1058 GetTempFileNameA() takes an optional prefix, and a "unique" long value which can optionally be zero, which causes it to automatically increment until a not-yet-existing filename is found. When libevent creates many AF_UNIX socketpairs on windows, it slows down dramatically, due to always using the same blank prefix, and GetTempFileNameA() needing to iterate through all the existing socketpair filenames. With a present and varying prefix, it will have much less need to iterate. It was also possible for a race with other processes also using blank-prefix tmpfile names to result in both trying to start using the same name at the same time (because libevent deletes the file and then re-creates it as a unix socket), which should now be much less likely. Unfortuantely, "much" is just a factor of 32k, because the prefix is only 3 characters, and windows filesystems are case-insensitive, so doing better would require more sophisticated windows API usage and charset trickyness.
* http: fix undefined-shift in EVUTIL_IS*_ helpersAzat Khuzhin2020-06-251-1/+1
| | | | | | | | | | | | | | evutil.c:2559:1: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' #0 0x4f2be0 in EVUTIL_ISXDIGIT_ libevent/evutil.c:2559:1 #1 0x4bd689 in regname_ok libevent/http.c:4838:7 #2 0x4bc16b in parse_authority libevent/http.c:4958:9 #3 0x4bb8b5 in evhttp_uri_parse_with_flags libevent/http.c:5103:7 #4 0x4bb762 in evhttp_uri_parse libevent/http.c:5050:9 #5 0x4b8f41 in evhttp_parse_query_impl libevent/http.c:3505:9 #6 0x4b8ed7 in evhttp_parse_query libevent/http.c:3569:9 Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23291 Report: https://oss-fuzz.com/testcase-detail/5670743106125824
* There is typo in GetAdaptersAddresses windows library. It should be iphlpapi.dllAleksandr-Melnikov2020-05-051-1/+1
|
* Parse IPv6 scope IDs.Philip Homburg2019-11-061-2/+48
|
* evutil: make evutil_socketpair() have the same behavior on Windows with ↵yuangongji2019-10-181-7/+13
| | | | build number lower and higher than 17063
* evutil: implement socketpair with unix domain socket on Win10yuangongji2019-10-141-2/+177
|
* Missing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYSyuangongji2019-07-111-0/+1
|
* evutil: drop force_check from evutil_check_interfaces() (unused)Azat Khuzhin2019-06-151-3/+3
|
* evutil: set the have_checked_interfaces in evutil_check_interfaces()jeremyerb2019-06-151-2/+4
| | | | | Closes: #836 (cherry-picked) Fixes: #834
* Check existence of IPV6_V6ONLY in evutil_make_listen_socket_ipv6only() (mingw32)Azat Khuzhin2018-10-281-0/+3
| | | | | | | | | | | | | MinGW 32-bit 5.3.0 does not defines it and our appveyour [1] build reports this instantly: evutil.c: In function 'evutil_make_listen_socket_ipv6only': evutil.c:392:40: error: 'IPV6_V6ONLY' undeclared (first use in this function) return setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void*) &one, [1]: https://www.appveyor.com/docs/windows-images-software/#mingw-msys-cygwin Another solution will be to use mingw64 which has it, but I guess we do want that #ifdef anyway.
* listener: ipv6only socket bind supportMurat Demirten2018-10-261-0/+8
| | | | | | | | | | | | | | According to RFC3493 and most Linux distributions, default value is to work in IPv4-mapped mode. If there is a requirement to bind same port on same ip addresses but different handlers for both IPv4 and IPv6, it is required to set IPV6_V6ONLY socket option to be sure that the code works as expected without affected by bindv6only sysctl setting in system. See an example working with this patch: https://gist.github.com/demirten/023008a63cd966e48b0ebcf9af7fc113 Closes: #640 (cherry-pick)
* Split evutil_found_ifaddr() into helpers (evutil_v{4,6}addr_is_local())Azat Khuzhin2018-10-251-20/+26
|
* Use INADDR_ANY over 0 in evutil_found_ifaddr()Azat Khuzhin2018-10-251-1/+1
|
* Replace EVUTIL_V4ADDR_IS_*() macroses with static inline functionsAzat Khuzhin2018-10-251-14/+14
| | | | | | Macros over static inline over and over again: - readability - type safety
* Filter link-local IPv4 addresses in evutil_found_ifaddr()Azat Khuzhin2018-10-251-0/+6
| | | | Fixes: #668
* fix evutil_make_internal_pipe_'s comment that fd[0] for read and f[1] for writeXiang Zhang2017-03-181-1/+1
|
* evutil: fix a typo of commenttim-le2017-03-051-1/+1
| | | | | Fixes: #481 Fixes: #480
* evutil: mark ai_find_protocol() static (prototype-less)Azat Khuzhin2016-08-101-1/+1
|
* Fix getaddrinfo under solaris (for multiprotocol case)Azat Khuzhin2016-08-101-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | During testing on solaris 11.3, util/getaddrinfo failed at: memset(&hints, 0, sizeof(hints)); hints.ai_flags = EVUTIL_AI_NUMERICHOST; r = evutil_getaddrinfo("1.2.3.4", NULL, &hints, &ai); tt_assert(ai_find_by_protocol(ai, IPPROTO_TCP)); And this is because solaris's getaddrinfo() returns: $6 = { ai_flags = 32, ai_family = 2, ai_socktype = 0, ai_protocol = 0, <-- no proto ai_addrlen = 16, ai_canonname = 0x0, ai_addr = 0x815d658, ai_next = 0x0 <-- nothing else } So we should emulate this too. Plus introduce helper that will search through all results, not only first one. Fixes: util/getaddrinfo Fixes: #354
* evdns: export cancel via callbacks in util (like async lib core/extra issues)Azat Khuzhin2016-03-231-4/+18
|
* evutil_parse_sockaddr_port(): fix buffer overflowAzat Khuzhin2016-02-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | @asn-the-goblin-slayer: "Length between '[' and ']' is cast to signed 32 bit integer on line 1815. Is the length is more than 2<<31 (INT_MAX), len will hold a negative value. Consequently, it will pass the check at line 1816. Segfault happens at line 1819. Generate a resolv.conf with generate-resolv.conf, then compile and run poc.c. See entry-functions.txt for functions in tor that might be vulnerable. Please credit 'Guido Vranken' for this discovery through the Tor bug bounty program." Reproducer for gdb (https://gist.github.com/azat/be2b0d5e9417ba0dfe2c): start p (1ULL<<31)+1ULL # $1 = 2147483649 p malloc(sizeof(struct sockaddr)) # $2 = (void *) 0x646010 p malloc(sizeof(int)) # $3 = (void *) 0x646030 p malloc($1) # $4 = (void *) 0x7fff76a2a010 p memset($4, 1, $1) # $5 = 1990369296 p (char *)$4 # $6 = 0x7fff76a2a010 '\001' <repeats 200 times>... set $6[0]='[' set $6[$1]=']' p evutil_parse_sockaddr_port($4, $2, $3) # $7 = -1 Before: $ gdb bin/http-connect < gdb (gdb) $1 = 2147483649 (gdb) (gdb) $2 = (void *) 0x646010 (gdb) (gdb) $3 = (void *) 0x646030 (gdb) (gdb) $4 = (void *) 0x7fff76a2a010 (gdb) (gdb) $5 = 1990369296 (gdb) (gdb) $6 = 0x7fff76a2a010 '\001' <repeats 200 times>... (gdb) (gdb) (gdb) (gdb) Program received signal SIGSEGV, Segmentation fault. __memcpy_sse2_unaligned () at memcpy-sse2-unaligned.S:36 After: $ gdb bin/http-connect < gdb (gdb) $1 = 2147483649 (gdb) (gdb) $2 = (void *) 0x646010 (gdb) (gdb) $3 = (void *) 0x646030 (gdb) (gdb) $4 = (void *) 0x7fff76a2a010 (gdb) (gdb) $5 = 1990369296 (gdb) (gdb) $6 = 0x7fff76a2a010 '\001' <repeats 200 times>... (gdb) (gdb) (gdb) (gdb) $7 = -1 (gdb) (gdb) quit Fixes: #318
* Merge pull request #296 from lzmths/masterMark Ellzey2015-12-141-5/+6
|\ | | | | Refactoring conditional directives that break parts of statements.
| * Refactoring conditional directives that break parts of statements.lzmths2015-12-141-5/+6
| |
* | Fixed Unicode issue in error messages.Mattes D2015-12-141-2/+2
|/
* Test against SO_REUSEADDR (along with _WIN32).Ed Schouten2015-09-021-1/+1
| | | | | | | | | | This makes the code build on other systems that also don't have SO_REUSEADDR without requiring special code. [ azat: partially revert WIN32 check since SO_REUSEADDR on win32 differs from unix semantics. ] Closes #275
* Don't use BSD u_* types.Ed Schouten2015-08-251-1/+1
| | | | | | These types are not part of POSIX. As we only use them in a small number of places, we'd better replace them by C standard types. This makes a larger part of the code build for CloudABI.
* util: make @sa const for evutil_socket_connect_()Azat Khuzhin2015-08-181-1/+1
|
* Set correct socklen for PF_INET6 sockaddr lenMark Ellzey2015-06-011-1/+1
| | | | Reported and patched by Pankaj Sharma
* Fix garbage value in socketpair util function, stdint?Mark Ellzey2015-05-111-0/+3
| | | | | | | | | | * Fixed an issue with evutil_ersatz_socketpair_, listen_addr could all be compared against with agarbage values. So just memset it before using it anywhere. * Nick might punch me in the face, but if we have stdint.h; (as in EVENT__HAVE_STDINT_H is defined), might as well use those instead of the manual [U]INT[X}_MAX/MIN muck in there now.
* Provide support for SO_REUSEPORT through LEV_OPT_REUSABLE_PORTMaciej Soltysiak2014-10-131-0/+14
|
* Change return type of evutil_load_windows_system_library_ to HMODULENick Mathewson2014-08-291-2/+2
| | | | Noted by Miles Chan as issue #146
* Fix ubsan warnings when parsing ipv4/ipv6 addrsNick Mathewson2014-03-181-12/+12
| | | | | left-shifting a one-byte integer by 24 invokes undefined behavior. Let's not do that.
* Change all uses of WIN32 to _WIN32Joakim Söderberg2014-01-211-1/+1
|
* Merge remote-tracking branch 'origin/patches-2.0'Nick Mathewson2013-08-191-0/+12
|\ | | | | | | | | Conflicts: util-internal.h
| * Really remove RNG seeds from the stackNick Mathewson2013-08-191-0/+12
| |
* | Merge remote-tracking branch 'origin/patches-2.0'Nick Mathewson2013-05-291-1/+1
|\ \ | |/
| * Use windows vsnprintf fixup logic on all windows environmentsNick Mathewson2013-05-291-1/+1
| | | | | | | | | | | | Previously I'd relied on mingw to provide a vsnprintf with a conformant return value. But it appears that some mingw environments don't do that.
* | Avoid redundant syscall if making a socket cloexec twiceNick Mathewson2013-05-201-3/+5
| | | | | | | | I got the idea from Maxime's last patch.
* | Avoid redundant syscall to make a nonblocking socket nonblockingMaxime Henrion2013-05-201-3/+5
| |
* | Fix another warning introduced in 0c6ec5d8Nick Mathewson2013-04-251-1/+1
| |
* | Fix a warning introduced in 0c6ec5d8Nick Mathewson2013-04-251-1/+1
| |
* | use hashtable instead of linked list to cache winsock errorsPatrick Pelletier2013-02-251-20/+62
| | | | | | | | | | as discussed here: https://github.com/libevent/libevent/pull/41#issuecomment-13611817