<feed xmlns='http://www.w3.org/2005/Atom'>
<title>fortify-headers/include/wchar.h, branch master</title>
<subtitle>Standalone portable header-based implementation of FORTIFY_SOURCE=3 
</subtitle>
<id>http://git.dustri.org/fortify-headers/atom?h=master</id>
<link rel='self' href='http://git.dustri.org/fortify-headers/atom?h=master'/>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/'/>
<updated>2026-04-30T22:44:53Z</updated>
<entry>
<title>Fix strncat/wcsncat</title>
<updated>2026-04-30T22:44:53Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2026-04-30T22:36:32Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=ddd22b2f533db9c0da0bb262fbafa51f67c8587e'/>
<id>urn:sha1:ddd22b2f533db9c0da0bb262fbafa51f67c8587e</id>
<content type='text'>
Previously, no checks were done when __n &lt;= __b, but strncat _appends_ after
existing content, making this a overly broad check check. For example, with an
8-byte buffer containing "12345\0", strncat(buf, "ABCD", 4) would have the
check skipped, but the result "12345ABCD\0" is 10 bytes, resulting in an
overflow.

This commit fixes this oversight, and adds a bunch of tests.
</content>
</entry>
<entry>
<title>Fix mbsnrtowcs</title>
<updated>2026-04-30T16:06:56Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2026-04-30T16:06:56Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=d6105aba5fd791e8d3f069e771517cdb947b5604'/>
<id>urn:sha1:d6105aba5fd791e8d3f069e771517cdb947b5604</id>
<content type='text'>
mbsnrtowcs writes up to __wn wide characters into wchar_t *__d. The destination
capacity is __b / sizeof(wchar_t) wide characters, but the
else branch clamps __n (source byte limit) to __b (destination byte size).

__wn (the actual output count) is passed through unclamped. Example: __b=8
(dest holds 2 wchar_t), __n=100, __wn=25. The else branch applies (25 &lt;=
100/4), clamps source to 8 bytes, but passes __wn=25 — the function can write
25 wchar_t (100 bytes) into an 8-byte buffer.

The first branch is also wrong: it divides __b (bytes) by sizeof(wchar_t) to
get wchar_t capacity, which is correct for the destination — but the condition
__wn &gt; __n / sizeof(wchar_t) uses integer division that can produce incorrect
routing between branches.

The fix mirrors the already-correct mbsrtowcs pattern: clamp __wn (the output
wide-char count) to the destination's wchar_t capacity, and pass __n (source
byte limit) through unchanged.
</content>
</entry>
<entry>
<title>Improve coverage for wmemcpy and wmemmove</title>
<updated>2026-04-30T15:50:27Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2026-04-30T15:50:27Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=dfdf53df99c8f59e5e3a4296c455041bee96a88d'/>
<id>urn:sha1:dfdf53df99c8f59e5e3a4296c455041bee96a88d</id>
<content type='text'>
Like it's already done for memcpy and memmove. Add tests as well,
to prove that nothing broke.
</content>
</entry>
<entry>
<title>Fix a bug in wcsnrtombs</title>
<updated>2026-04-30T15:42:29Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2026-04-30T15:42:29Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=f9239e2c0f0be9856322727887a45333683940a6'/>
<id>urn:sha1:f9239e2c0f0be9856322727887a45333683940a6</id>
<content type='text'>
__d is a char * destination buffer, so __b is already the byte capacity.
Dividing by sizeof(wchar_t) makes no sense here, it was likely copy-pasted
from mbsnrtowcs (where the destination is wchar_t *). The first branch also
fails to limit __n (the byte write cap) to __b, so overflows are possible when
a wide character produces multi-byte output. The second branch (else) correctly
limits __n to __b.

This commit replaces the broken two-branch logic with the simple correct
pattern matching wcsrtombs, and adds two tests two prove that nothing broke.
</content>
</entry>
<entry>
<title>Remove wctomb</title>
<updated>2025-11-10T22:55:25Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2025-10-31T20:08:47Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=bc2641769ec3019ab7d794b032a6e36030581c76'/>
<id>urn:sha1:bc2641769ec3019ab7d794b032a6e36030581c76</id>
<content type='text'>
It's unfortunately valid to pass a buffer smaller than MB_CUR_MAX to wctomb, so
let's not trap on this. Moreover, it's supposed to be implemented in stdlib.h
and not wchar.h anyway.
</content>
</entry>
<entry>
<title>add initial clang support</title>
<updated>2025-10-31T21:16:21Z</updated>
<author>
<name>Daniel Kolesa</name>
</author>
<published>2022-10-25T22:30:00Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=f46714c2f9eb13c12c8218f1b7c045182041fdc9'/>
<id>urn:sha1:f46714c2f9eb13c12c8218f1b7c045182041fdc9</id>
<content type='text'>
Co-Authored-By: jvoisin &lt;julien.voisin@dustri.org&gt;
</content>
</entry>
<entry>
<title>avoid __extension__ with clang</title>
<updated>2025-10-31T21:16:21Z</updated>
<author>
<name>Daniel Kolesa</name>
</author>
<published>2022-11-01T19:14:54Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=8915dc13de44fed3a076a9fd51eb1ab2b5502d7b'/>
<id>urn:sha1:8915dc13de44fed3a076a9fd51eb1ab2b5502d7b</id>
<content type='text'>
It seems useless and triggers 'error: expected external declaration'
</content>
</entry>
<entry>
<title>Make use of __builtin_dynamic_object_size</title>
<updated>2025-10-31T21:16:21Z</updated>
<author>
<name>jvoisin</name>
</author>
<published>2023-03-18T13:01:02Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=249492e08adbf034976770ab3b021ba093a2ab18'/>
<id>urn:sha1:249492e08adbf034976770ab3b021ba093a2ab18</id>
<content type='text'>
GCC and Clang provide __builtin_dynamic_object_size
(see documentation: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html),
so we should make use of it when its available.
</content>
</entry>
<entry>
<title>wctomb, wcrtomb: guard slow/trap path with MB_LEN_MAX</title>
<updated>2019-03-07T00:05:34Z</updated>
<author>
<name>info@mobile-stream.com</name>
</author>
<published>2019-03-06T13:28:48Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=9b796691eb794e9f5279886e917c028a09f8a728'/>
<id>urn:sha1:9b796691eb794e9f5279886e917c028a09f8a728</id>
<content type='text'>
This allows the compiler to optimize out the slow/trap path at all
for the typical correct code:

char buf[MB_LEN_MAX];
r = wctomb(buf, c);

The change tries to keep the "unknown object size" case handling in
wcrtomb() as is even if it seems redundant and not helping (we copy
__buf to possibly undersized __s in any case) and inconsistent with
wctomb() (where we let the original library method itself overwrite
the possibly undersized __s).
</content>
</entry>
<entry>
<title>Make use of builtins whenever possible</title>
<updated>2019-02-25T13:17:08Z</updated>
<author>
<name>sin</name>
</author>
<published>2019-02-25T13:01:12Z</published>
<link rel='alternate' type='text/html' href='http://git.dustri.org/fortify-headers/commit/?id=5aabc7e6aad28327d75671e52c50060e4543112c'/>
<id>urn:sha1:5aabc7e6aad28327d75671e52c50060e4543112c</id>
<content type='text'>
</content>
</entry>
</feed>
