Files
freeswitch/tests/unit
Dmitry Verenitsin 28fcfd2624 Merge commit from fork
* Merge commit from fork

* [core] Fix XML escape encoder overrun and unsigned-char UTF-8 gate

`switch_xml_ampencode()` had two independent defects in its UTF-8
numeric-escape path.

Buffer overrun: the encoder grows its destination once per source byte,
but the realloc margin reserved only the 10 data characters of the
widest escape `"&#x%X;"` (a 21-bit code point rendered as 6 hex digits),
not the terminating NUL that `sprintf` also writes. At the margin
boundary that NUL landed one byte past the allocation. Reserve 11 bytes
in the guard (10 data chars plus the NUL) and emit the escape with
`snprintf` bounded to the remaining space, so the write stays in bounds
even if the margin is ever miscounted. The other escape sinks are all
within the widened margin and are unchanged.

Char signedness: the lead-byte test `(*s >> 8) & 0x01` reads bit 8 of a
plain `char`, which exists only after sign extension. Where `char` is
signed the high bit sign-extends and the test passes; where `char` is
unsigned it is always zero, so the numeric-escape path never ran and
multi-byte UTF-8 was emitted raw, making serialized XML differ by
architecture. Test bit 7 directly with `(*s & 0x80)`, correct regardless
of `char` signedness. This also makes the overrun fix effective on
unsigned-`char` builds, where the escape path now runs.

Add unit test `test_utf_8_wide_codepoint`, which serializes U+10FFFF and
long runs of it across buffer reallocations, sweeping an ASCII prefix so
an escape is emitted at the minimum-headroom offset, and asserts the
full serialized length.
2026-08-08 21:02:15 +03:00
..
2026-08-08 17:48:05 +03:00
2019-11-21 22:06:14 +04:00
2026-05-26 22:02:42 +03:00
2025-07-31 19:38:54 +03:00
2024-12-03 21:30:46 +01:00
2026-08-08 19:47:47 +03:00
2024-12-03 21:30:46 +01:00
2024-10-11 20:16:39 +02:00
2024-12-03 21:30:46 +01:00
2026-08-08 19:47:47 +03:00
2026-08-08 18:18:50 +03:00
2026-08-08 18:29:25 +03:00
2026-08-08 17:03:47 +03:00
2021-04-27 13:54:32 -06:00
2026-08-08 21:02:15 +03:00
2026-08-08 17:48:05 +03:00
2026-05-26 22:02:42 +03:00
2024-12-03 21:30:46 +01:00

FreeSWITCH unit tests should be kept as shallow unit tests and micro
benchmarks testing functionality exposed through libfreeswitch.

Requirements for a new unit tests: 

1. Tests must use switch_test.h framework