1
0
mirror of https://github.com/coturn/coturn.git synced 2026-04-03 19:30:59 +02:00

1037 Commits

Author SHA1 Message Date
Carlos Ruiz Ballesteros
a4756d482f
fix: restore RFC 3489 (old STUN) backward compatibility broken since 4.7.0 (#1839)
## Problem

Since 4.7.0, `--stun-backward-compatibility` no longer works. Legacy
STUN clients (RFC 3489, pre-magic-cookie) receive no response even when
the option is explicitly enabled.

## Root Cause

Commit 4cc076d renamed `no_stun_backward_compatibility` (negative logic)
to `stun_backward_compatibility` (positive logic). Two call sites were
not updated correctly:

1. **`src/server/ns_turn_server.c`**: the
`old_stun_is_command_message_str` branch in the TCP/stream socket
handler kept `!` on the renamed variable, inverting the condition. Old
STUN was processed only when backward compat was *off*.

2. **`src/apps/relay/dtls_listener.c`**: the UDP/DTLS early packet
validation block never included an `old_stun_is_command_message_str`
check, so old STUN packets were always classified as invalid regardless
of the backward compat flag.

## Fix

- **`ns_turn_server.c`**: Remove the stray `!` negation restoring
correct condition semantics.
- **`dtls_listener.c`**: Add the missing old-STUN branch in the UDP
packet validation block, guarded by
`turn_params.stun_backward_compatibility`.
2026-03-25 23:16:21 -07:00
redraincatching
86e5e72718
Change port identifiers to use uint16_t (#1752)
based on the ideas originally developed in [this
pr](https://github.com/coturn/coturn/pull/1535) by @WHYHD

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2026-03-14 19:47:15 -07:00
Pavel Punsky
75f8133c40
Fixes: run_tests.sh and no db (#1834) 2026-03-12 22:01:28 -07:00
mesibo
65c4445227
Add session usage reporting callback to TURN database driver (#1794)
We use Coturn in production at [mesibo](https://mesibo.com) and
identified a gap in dbdriver: there's no callback to capture
post-session metrics like duration, bandwidth consumed, timestamps, etc.

We've made the following changes, which could be useful for Coturn.
Would appreciate your consideration. These changes are tested in
production environments at mesibo.

## Changes for reporting usage

Added a `report_usage` callback to the database driver interface,
invoked at session termination. This allows drivers to capture and
persist detailed usage statistics in their preferred storage (MySQL,
PostgreSQL, etc.).

### 1. Database Driver Interface
**File:** `src/apps/relay/dbdrivers/dbdriver.h`

```c
typedef struct _turn_dbdriver_t {
    // ... existing callbacks
    void (*report_usage)(void *);
} turn_dbdriver_t;
```

### 2. Session Termination Hook
**File:** `src/apps/relay/ns_ioalib_engine_impl.c`

```c
void turn_report_session_usage(void *session, int force_invalid) {
    // ... existing code
    
    if(force_invalid) {
        const turn_dbdriver_t * dbd = get_dbdriver();
        if(dbd->report_usage)
            dbd->report_usage(session);
    }

   // ... existing code
   ss->received_packets = 0;
   ...
}
```

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2026-03-08 19:48:54 -07:00
Pavel Punsky
44d201a4f9
Initialize variables before use (#1832) 2026-03-08 16:24:32 -07:00
Pavel Punsky
dbfa9dbb53
Replace perror with logging (#1831)
Replace all calls to `perror` with log message

perror printed messages do not follow logging format, sometimes provided
duplicate information
2026-03-08 16:24:00 -07:00
Pavel Punsky
9467af5041
CLI interface is disabled by default (#1830)
cli interface is ON by default which creates a security risk (even
though requires a password) and recommended to be disabled.
Instead of just recommendation, this PR disables CLI by default and now
requires an explicit flag to enable it

If using old configuration or cli arguments to turnserver - it will log
an error message about `--no-cli` being deprecated while doing nothing
(already disabled). This log line will be removed in the future
2026-03-06 18:00:45 -08:00
Pavel Punsky
20d8e38297
Disable reason string in response messages to reduce amplification factor (#1829)
Disable the messages by default - they can be re-enabled using
`--include-reason-string` option

As a result of not sending reason string (which is optional by standard
and provide debugging information for the actual numeric error code)
response message size can be decreased by up to NNN bytes.
2026-03-06 17:59:21 -08:00
Pavel Punsky
00519cd2b5
Perf: improve worst case scenario optimization (#1823)
Memory allocation performance optimizations:
- Replaced a heap-allocated buffer with a stack-allocated one in
generate_cookie():
- Optimized buffer reuse in the UDP server's packet receive loop -
reduces unnecessary allocations/frees in the hot path of the UDP batch
receive loop (especially during DDoS)
2026-03-01 20:57:33 -08:00
Pavel Punsky
ec0719c421
Fix compilation warnings (#1822)
Resolve multiple compilation warnings:
- unused argument
- type conversion
2026-02-28 19:45:16 -08:00
Pavel Punsky
41ba6d8f5d
Update version to 4.9.0 (#1813)
Update version to 4.9.0 

Contains security fixes and highly recommended to upgrade
2026-02-23 17:04:31 -08:00
Pavel Punsky
e59f0ffeaa
Fix thread sanitizer warning (#1812)
Resolves all sanitizer warnings caused by
1. simultaneous access to logger time
2. barrier during threads initialization at startup
2026-02-23 16:16:27 -08:00
Pavel Punsky
da30d26ea3
Temporary workaround for windows build (#1811) 2026-02-22 22:57:29 -08:00
Pavel Punsky
b80eb898ba
Merge commit from fork
* Handle IN6_IS_ADDR_V4MAPPED mappings

* Handle IN6_IS_ADDR_V4MAPPED mappings
2026-02-22 19:18:42 -08:00
Pavel Punsky
e5ed78583d
Fixes: int to bool conversion and comparison (#1810)
In multiple places int is converted to bool
2026-02-21 18:27:16 -08:00
Pavel Punsky
4c674289a8
OpenSSL: migrate to modern API for DH param (#1809)
Use openssl-3.0 apis
2026-02-21 17:31:17 -08:00
Pavel Punsky
6c38ccb08d
Migrate AES-128 encryption from deprecated OpenSSL API to EVP (#1808)
The AES_encrypt, AES_set_encrypt_key, CRYPTO_ctr128_encrypt, and
SSL_CTX_use_RSAPrivateKey_file functions are deprecated in OpenSSL 3.0+
and produce compiler warnings.Replace deprecated low-level OpenSSL
AES/CRYPTO functions with the modern EVP (Envelope) API, and remove the
deprecated SSL_CTX_use_RSAPrivateKey_file fallback.

Changes
encrypt_aes_128 — Replaced AES_set_encrypt_key + CRYPTO_ctr128_encrypt
with EVP_EncryptInit_ex / EVP_EncryptUpdate / EVP_EncryptFinal_ex using
EVP_aes_128_ctr(). Added proper error handling (context cleanup on
failure), input length bounds checking, and enlarged the total buffer
from 256 to 1024 bytes to match the output buffer. The IV was corrected
from 8 to 16 bytes (as required by AES-CTR).

decrypt_aes_128 — Same migration from CRYPTO_ctr128_encrypt to
EVP_DecryptInit_ex / EVP_DecryptUpdate / EVP_DecryptFinal_ex. Added
proper cleanup of both the EVP context and the encryptedText allocation
on every error path. Retained the existing bounds check on newTotalSize.
Output is now explicitly null-terminated using the actual decrypted
length (outlen + final_len).

set_ctx (TLS context setup) — Removed the SSL_CTX_use_RSAPrivateKey_file
fallback that was nested inside the SSL_CTX_use_PrivateKey_file failure
path. SSL_CTX_use_PrivateKey_file already handles RSA keys, so the
RSA-specific fallback was redundant and used a function deprecated since
OpenSSL 3.0.
2026-02-19 18:05:05 -08:00
Pavel Punsky
b209191ba1
Fix unbounded strcpy in stun_method_str (ns_turn_msg.c) (#1798)
## Issue
strcpy(smethod, s) with no size check. Callers pass fixed buffers (e.g.
32 bytes); if API were misused with a smaller
buffer, or s were ever longer, this could overflow.

## Fix
Use strncpy with a fixed maximum (32), then null-terminate,
so at most 32 bytes are written regardless of caller buffer size.
2026-02-16 21:23:10 -08:00
Pavel Punsky
667b661e80
Fix missing null termination in addr_to_string (ns_turn_ioaddr.c) (#1806)
## Issue
Multiple changes in this PR related to address printing (with and
without port)
- Change buffer size to be 64 (enough to hold IPv6 - 46, and port - 5,
and formatting "[ip]:port")
- Align buffer size across all usages (were 65, 129, 256, 257, 1025).
Even 65 is bad - takes extra cache line.
- Change argument to `addr_to_string_no_port`/`addr_to_string` to be of
type char inasted of uint8_t (double converted)
- Eliminate extra buffer in `addr_to_string_no_port`
- Defensively terminate string with null in addr_to_string`

## Explanations
- `addr_to_string_no_port` rely on `inet_ntop` to convert address to
null terminated string
- `addr_to_string` with port==0 rely on `inet_ntop`, otherwise null
terminate at the end of the buffer of size MAX_IOA_ADDR_STRING
2026-02-16 21:20:41 -08:00
Pavel Punsky
77f99e0995
Fix missing null termination after strncpy in DB drivers (#1804)
## Issue
strncpy(realm/pwd, ..., STUN_MAX_*_SIZE) does not append a null. When DB
value length >= size, the buffer was
unterminated, leading to potential reads past buffer in later code.

## Fix
Explicitly set realm[STUN_MAX_REALM_SIZE] and pwd[STUN_MAX_PWD_SIZE] to
'\0' after each strncpy.
2026-02-16 19:19:02 -08:00
Pavel Punsky
ad85332c94
Fix unbounded strcpy in HTTP response (http_server.c) (#1800)
## Issue
strcpy(data, data_http) copied into the network buffer
with no size check. If buffer allocation or layout changed, this
could overflow.

## Fix
Use ioa_network_buffer_get_capacity(), copy at most that many
bytes with memcpy, explicitly null-terminate, and set size accordingly.
2026-02-15 18:48:24 -08:00
Pavel Punsky
84f492ad6e
Fix buffer overflow in decryptPassword in mysql (#1801)
## Issue
strcat(last, (char *)outdata) then strcpy(out, last) with last[1024].
outdata is not null-terminated (decryption output),
allowing reads past buffer and possible overflow of last.

## Fix
Use bounded memcpy with explicit null termination, limiting copy to
remaining space in last and sizeof(outdata). Check malloc before strcpy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-15 18:22:56 -08:00
Pavel Punsky
bdacef780b
Fix missing null termination after strncpy in MongoDB driver (dbd_mongo.c) (#1797)
## Issue
strncpy(realm/pwd, ...) without null termination
when source is long left buffers unterminated.

## Fix
Set realm[STUN_MAX_REALM_SIZE] and pwd[STUN_MAX_PWD_SIZE]
to '\0' after each strncpy.
2026-02-15 17:50:40 -08:00
Pavel Punsky
b69ceb4252
Fix buffer overflow in decrypt_aes_128 (#1799)
**Issue**: 

strcat(last, (char *)outdata) was used with a fixed
buffer last[1024]. outdata is decryption output that is not
null-terminated (CRYPTO_ctr128_encrypt writes newTotalSize bytes). This
could read past outdata and/or overflow last if decrypted size grew.

**Fix**: 

Replace with bounded copy using memcpy and explicit null
termination, limiting bytes copied to remaining space in last and to
sizeof(outdata).
2026-02-15 17:42:01 -08:00
薄景仁
7f7dc99d3e
Urgent! Fix Web Admin Password Check (#1802)
The password check for web admin is reversed, so users can login with
the wrong password. 

Fixes #363, #1216
2026-02-12 21:09:12 -08:00
Pavel Punsky
0177bcd373
Update version to 4.8.0 (#1791)
Update version to 4.8.0 
Set new release version to 4.8.0

Contains security fixes and highly recommended to upgrade
2026-01-05 17:35:27 -08:00
Pavel Punsky
11fc465f4b
Merge commit from fork
This returns the code to the state before #1279 that made turn_random() less secure and introduced more secure version with urn_random_number()  (which is actually the same as turn_random() before the change)
2025-12-29 09:05:16 -08:00
Pavel Punsky
bae6bb3aed
Allow faster packet validation on listener threads (#1768)
Add CLI flag to enable early packet validation
Drop packets that do not pass basic STUN command/channel or DTLS parsing

Before this change, no validation on packets were done and they were
passed (through libevent queue) to relay thread pool. Relay thread
would, for a new source, allocate a new SS (18KB) which will only be
released after 1s of no traffic, and then do the validation.

So with old code, invalid packet would have extra:
- Queuing
- Processing on a different thread
- Memory allocation of 18KB

Assuming DDoS attack is spoofing IPs it reduces processing capacity
dramatically.
Testing possible by:
```
hping3 -2 -p 3478 -d 2 -rand-source --flood turn_ip
```

which floods `turn_ip:3478` with packets of size 2 from random sources.
Size 2 is especially bad case - the packet is obviously invalid (too
short) but still goes through a long process of queuing, thread
switching, memory allocation and only then validation (and then memory
cleanup etc). In worst cases, memory is never cleaned up because sources
repeat.
2025-12-29 09:04:25 -08:00
Pavel Punsky
c7936e449b
Fix order of arguments to calloc (#1790)
Proper use of the api: count and then size
This gives a warning on some of the compilers
2025-12-28 11:39:01 -08:00
Pavel Punsky
21ddce65be
Fix crashes while setting socket buffer size (#1789)
Some places in code do not have access to the buffer size which result
in crash which can be seen in tests
This PR removes the call to `set_ioa_socket_buf_size` from those places
(which is redundant anyway)
2025-12-26 21:10:24 -08:00
Pavel Punsky
59921981bb
Implement configurable buffer sizes (#1780)
# Description

Replace the hardcoded buffer sizes inside coturn to make them
configurable for different use cases (low bitrate use cases can save
memory and high bitrate use case can avoid congestion) - based on #1089

Add this feature in both sides (listener and relay connections).

# Tests

For now it is only the automated CI tests.
Confirmed with debugger that buffer sizes are set according to the
arguments.
2025-12-25 14:06:28 -08:00
Pavel Punsky
265d1029e6
Use bool to enable prometheus (#1779)
`turn_params.prometheus` is bool but used as int throughout the code
`turn_params,prometheus_username_labels` is bool but in one place is set
with 1

This PR changes 0 and 1 to false and true accordingly
2025-12-08 08:43:36 -08:00
Pavel Punsky
63447a763a
Fix memory leak using libevent (#1751)
Fixes #1750
2025-09-28 21:00:44 -07:00
redraincatching
b1dddb5f49
addressed possible null pointer dereferences (#1729)
this pr aims to address more static code analyser warnings, specifically
null pointer dereferences. the majority of changes are solely to quieten
the analyser, as `malloc` and `calloc` are unlikely to fail, but this
should at least lead to the code analysis being more readable and
usable.

where functions addressed had existing failure strategies, they were
used, however some functions will now silently fail rather than
attempting to dereference a null pointer. if there is a preferred
solution in these cases, i will be happy to implement it.

---

-
[27](https://github.com/redraincatching/coturn/security/code-scanning/27):
moved use of pointer inside `else` block of null check
-
[42](https://github.com/redraincatching/coturn/security/code-scanning/42):
added early return in case of null pointer
-
[69](https://github.com/redraincatching/coturn/security/code-scanning/69):
added null pointer check after `malloc`
-
[76](https://github.com/redraincatching/coturn/security/code-scanning/76):
added null pointer check after `calloc`
-
[77](https://github.com/redraincatching/coturn/security/code-scanning/77):
added null pointer check to loop guard
-
[82](https://github.com/redraincatching/coturn/security/code-scanning/82):
added null pointer check after `malloc`
-
[83](https://github.com/redraincatching/coturn/security/code-scanning/83):
added null pointer check after `malloc`
-
[84](https://github.com/redraincatching/coturn/security/code-scanning/84):
added null pointer check after `calloc`
-
[85](https://github.com/redraincatching/coturn/security/code-scanning/85):
added null pointer check around pointer use, as done earlier in the same
function
-
[86](https://github.com/redraincatching/coturn/security/code-scanning/86):
added null pointer check after `calloc`
-
[90](https://github.com/redraincatching/coturn/security/code-scanning/90)/[91](https://github.com/redraincatching/coturn/security/code-scanning/91)/[92](https://github.com/redraincatching/coturn/security/code-scanning/92)/[93](https://github.com/redraincatching/coturn/security/code-scanning/93):
added null pointer check to block
-
[94](https://github.com/redraincatching/coturn/security/code-scanning/94)/[95](https://github.com/redraincatching/coturn/security/code-scanning/95):
added null pointer checks after `malloc`
-
[108](https://github.com/redraincatching/coturn/security/code-scanning/108):
added check after `calloc`
-
[114](https://github.com/redraincatching/coturn/security/code-scanning/114):
added check after `memcpy`
-
[129](https://github.com/redraincatching/coturn/security/code-scanning/129):
added check after `calloc`
-
[145](https://github.com/redraincatching/coturn/security/code-scanning/145):
added check to if guard
-
[146](https://github.com/redraincatching/coturn/security/code-scanning/146):
added check to if guard
-
[154](https://github.com/redraincatching/coturn/security/code-scanning/154):
added early exit with error
-
[165](https://github.com/redraincatching/coturn/security/code-scanning/165):
added check after `malloc`
-
[170](https://github.com/redraincatching/coturn/security/code-scanning/170):
added early null return on null pointer
-
[171](https://github.com/redraincatching/coturn/security/code-scanning/171):
added check after `calloc`

---
![You're dereferencing a null
pointer!](https://i.makeagif.com/media/9-29-2015/YwGqu_.gif)
2025-09-11 18:00:38 -07:00
redraincatching
2a9b77bd0b
address possible null pointer dereferences (#1744)
# addressing all remaining code scanning instances of warning C6011,
null pointer dereference

this pr aims to address more static code analyser warnings, specifically
null pointer dereferences. the majority of changes are solely to quieten
the analyser, as `malloc` and `calloc` are unlikely to fail, but this
should at least lead to the code analysis being more readable and
usable.

where functions addressed had existing failure strategies, they were
used, however some functions will now silently fail rather than
attempting to dereference a null pointer. if there is a preferred
solution in these cases, i will be happy to implement it.

---

this is an extension of [this pull
request](https://github.com/coturn/coturn/pull/1729)
2025-09-08 21:18:33 -07:00
Michael Jones
98d91a73cf
Improve const correctness in coturn (#1424)
Marking variables as const when they won't be modified after
initialization helps programmers trying to understand a codebase to
manage the cognative load.

This pull request uses a clang-tidy fixit (Hard to automate, since the
code needs to be temporarily compiled as C++ for it to work) to try to
mechanically apply the const keyword to code where the automated tool
can determine that the variable won't be modified.

I then follow this up with a manual improvement pass to
turnutils_uclient, where I address const correctness of local variables,
as well as do some adjustments to loops and scoping to help with
reducing complexity.

Co-authored-by: redraincatching <redraincatching@disroot.org>
Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2025-09-08 21:14:56 -07:00
Pavel Punsky
0749cd7efd
Update attribute values according to RFC 8656 (#1748)
Source https://datatracker.ietf.org/doc/html/rfc8656#section-18
Now conforms to RFC specification

- ADDITIONAL_ADDRESS_FAMILY (0x8000) - was (0x8032)
- ADDRESS_ERROR_CODE (0x8001) - was (0x8033)

Fixes #1740
2025-09-07 19:34:38 -07:00
Lidong Yan
439914716d
mainreplay: fix leak in decrypt_aes_128() (#1737)
In decrypt_aes_128() at src/apps/replay/mainreplay.c, it calls
base64decode() to allocates memory in encryptedText, but forgets to free
encryptedText in the end of this function. Add free() after finished
using encryptedText.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
2025-09-05 10:36:55 -07:00
Gustavo Garcia
6877e91c20
Fix logging before parsing logging cmd line args (#1723)
When using --log-file stdout to redirect turnserver logs to stdout
instead of creating a log file, a default log file was still being
created. This happened because the --log-file argument was processed
after logging had already occurred during startup.

Fix #1670
2025-07-14 15:44:34 +02:00
redraincatching
68ac0772d9
reduce calls to random (#1710)
implemented change suggested in TODO to speed up aes key generation
without, hopefully, negatively impacting the overall randomness of the
function

---------

Co-authored-by: Gustavo Garcia <gustavogb@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-11 12:42:28 +02:00
Gustavo Garcia
4de6c14f71
Fix null pointer dereference in set_ssl_ctx function (#1720)
This PR fixes a null pointer dereference vulnerability where
`set_ssl_ctx()` could crash when passed a NULL engine handle.

## Problem

The `create_ioa_engine()` function can return NULL when invalid
parameters are provided:

```c
if (!relays_number || !relay_addrs || !tp) {
  TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: Cannot create TURN engine\n", __FUNCTION__);
  return NULL;
}
```

However, two calling functions don't check for NULL before passing the
result to `set_ssl_ctx()`:

1. **`setup_relay_server()`** (line 1646):
   ```c
   rs->ioa_eng = create_ioa_engine(...);
set_ssl_ctx(rs->ioa_eng, &turn_params); // Potential NULL dereference
   ```

2. **`create_new_listener_engine()`** (line 955):
   ```c
   ioa_engine_handle e = create_ioa_engine(...);
   set_ssl_ctx(e, &turn_params);  // Potential NULL dereference
   ```

The `set_ssl_ctx()` function then dereferences the engine parameter
without checking:
```c
struct event_base *base = e->event_base;  // Crashes if e is NULL
```

## Solution

Added a simple check before calling `set_ssl_ctx()`:

## Impact

-  Prevents crashes when `create_ioa_engine()` fails due to invalid
configuration
-  Minimal change with no functional impact on normal operation
-  All existing tests continue to pass
-  Follows defensive programming best practices

Fixes #1718.
2025-07-11 12:40:28 +02:00
Copilot
99984fbccd
Add configurable CPU count option for containerized environments (#1717)
This PR adds a new `--cpus` configuration option to address CPU
detection issues in virtualized and containerized environments where
`_SC_NPROCESSORS_CONF` and `_SC_NPROCESSORS_ONLN` return host CPU counts
instead of allocated container CPUs.

## Problem
In containerized deployments, coturn detects the host's CPU count (e.g.,
128 CPUs) instead of the container's allocated CPUs (e.g., 2 CPUs). This
causes the server to create excessive relay threads and database
connections, leading to resource exhaustion and performance issues.

## Solution
Added a new `cpus` configuration option that allows manual override of
CPU detection:

### Command Line Usage
```bash
turnserver --cpus 2
```

### Configuration File Usage
```ini
# Override system CPU count detection for containers
cpus=2
```

## Key Features
- **Backward Compatible**: No changes needed for existing deployments
- **Input Validation**: Values must be between 1 and 128 with proper
error handling
- **Comprehensive Documentation**: Updated man pages and example config
files
- **Both Interfaces**: Works via command line and configuration file

## Testing
The implementation has been thoroughly tested:

```bash
# Container with 2 allocated CPUs on 128-CPU host
$ turnserver --cpus 2
INFO: System cpu num is 128       # Host detection
INFO: System enable num is 128    # Host detection  
INFO: Configured cpu num is 2     # Override applied
INFO: Total General servers: 2    # Correct thread count
```

-  Command line option: `--cpus 8` creates 8 relay servers
-  Config file option: `cpus=6` creates 6 relay servers  
-  Error handling: Invalid values show appropriate errors
-  Default behavior: Without option, uses system detection
-  RFC5769 tests: All protocol tests still pass

## Files Modified
- `src/apps/relay/mainrelay.c` - Core implementation
- `src/apps/relay/mainrelay.h` - Added configuration flag
- `examples/etc/turnserver.conf` - Added documentation and example
- `man/man1/turnserver.1` - Updated man page

This change directly addresses the resource consumption issues in
containerized environments while maintaining full backward
compatibility.

Fixes #1628.
2025-07-10 15:37:02 +02:00
lhywk
5ab95e1a5a
Fix memory and resource leaks in udp_create_server_socket( ) (#1714)
### Describe

Hi,

Fixes resource and memory leaks in `udp_create_server_socket()` by
ensuring that the socket file descriptor (`udp_fd`) and dynamically
allocated memory (`server_addr`) are properly released on failure.

Specifically, if `addr_bind()`, `event_new()`, or `event_add()` fails,
the function now closes the socket and frees memory to prevent leaks.

### Expected Behavior

On any failure during socket binding or event registration, both
`udp_fd` and `server_addr` should be released to avoid leaking system
resources.

### Actual Behavior

Previously, if `addr_bind()`, `event_new()`, or `event_add()` failed,
the function would return early without closing the socket or freeing
memory, causing file descriptor and heap memory leaks.

This patch addresses overlooked memory and resource cleanup on failure
paths, improving server stability through targeted and essential
changes.

Thanks for reviewing.

Co-authored-by: Gustavo Garcia <gustavogb@gmail.com>
2025-07-03 10:23:59 +02:00
Shane
2944775261
Add define to disable OAuth support (#1713)
Redoing https://github.com/coturn/coturn/pull/1664 as requested. This
adds an optional OAUTH_DISABLED define to allow for disabling OAuth
support.
2025-07-02 11:36:50 +02:00
redraincatching
0f8cdde961
typo correction (#1715)
@ggarber i noticed too late that i used `0x03` instead of `0x02` by
mistake - this is an issue because it means that `add_requested_family`
will never be set when ipv6 is being used, so this should be fixed
2025-07-01 14:10:45 +02:00
redraincatching
a3a7450104
refactored tri-state to bools (#1709)
refactored random tri-state to use two random booleans for clarity
2025-07-01 12:41:22 +02:00
redraincatching
16f801f646
addressed null pointer deref warnings (#1712)
addressing issues raised by code scanning, specifically null pointer
dereferences in server

ns_turn_server.c
-
[33](https://github.com/redraincatching/coturn/security/code-scanning/33)
ignored, the `is_rfc5780()` function exits early if the server is null
- this also catches
[36](https://github.com/redraincatching/coturn/security/code-scanning/36)
-
[34](https://github.com/redraincatching/coturn/security/code-scanning/34)
addressed
-
[174](https://github.com/redraincatching/coturn/security/code-scanning/174)
addressed

ns_turn_maps.c
-
[27](https://github.com/redraincatching/coturn/security/code-scanning/27),
[160](https://github.com/redraincatching/coturn/security/code-scanning/160),
[161](https://github.com/redraincatching/coturn/security/code-scanning/161),
[162](https://github.com/redraincatching/coturn/security/code-scanning/162),
[163](https://github.com/redraincatching/coturn/security/code-scanning/163),
[164](https://github.com/redraincatching/coturn/security/code-scanning/164),
[165](https://github.com/redraincatching/coturn/security/code-scanning/165)
false positives, suppressed with assert()

ns_turn_allocations.c
-
[9](https://github.com/redraincatching/coturn/security/code-scanning/9)
addressed

---------

Co-authored-by: Gustavo Garcia <gustavogb@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-01 12:40:11 +02:00
redraincatching
cb74638149
removed unnecessary null check (#1706)
removing an unnecessary null check as raised in [this code
scan](https://github.com/redraincatching/coturn/security/code-scanning/179)

the variable is confirmed to not be null in an outer loop guard

also changed the name of the variable in `rtcp_map_put`'s function
declaration to match that used in its function definition
2025-06-20 09:51:52 -07:00
Gustavo Garcia
62d91b0bc5
Fix compiler warnings in source files (#1704)
Two compiler warnings were addressed:

* In `src/apps/relay/http_server.c`, line 77, a `-Wpointer-sign` warning
occurred when initializing a `char *` with the `uint8_t *` return type
of `ioa_network_buffer_data()`.
* An explicit cast `(char *)` was added to
`ioa_network_buffer_data(nbh_http)` to resolve the type mismatch.

* In `src/apps/relay/acme.c`, line 59, a `-Wchar-subscripts` warning was
present because a `char` variable `c` was used as an array index. `char`
can be signed, potentially leading to negative indices.
* Initially, `c` was cast to `(unsigned char)` at the point of use:
`A[(unsigned char)c]`.
* This was later improved by changing the declaration of `c` from `const
char` to `const unsigned char c = req[k]

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2025-06-17 15:25:26 +02:00
redraincatching
afec2e2add
guarantee no oob write in strncat (#1702)
based on [this codescanning
alert](https://github.com/redraincatching/coturn/security/code-scanning/166)

guarantees that the `turn_params.cipher_list` will be null-terminated,
and that the call to strncpy cannot attempt to access out-of-bounds
memory
2025-06-12 11:15:46 +02:00