]> git.ipfire.org Git - thirdparty/systemd.git/commit
strxcpyx: add a paranoia check for vsnprintf()'s return value
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 17 Apr 2026 17:52:53 +0000 (19:52 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 19 Apr 2026 12:06:15 +0000 (14:06 +0200)
commit774a9f440bebeea960b69bb46109d72b3d7b8667
tree8f0a7b2cef44fffb0d52ede2c783189959765398
parentc859d41232b3bcff9f9b01f1281c1b202f15d0b2
strxcpyx: add a paranoia check for vsnprintf()'s return value

vsnprintf() can, under some circumstances, return negative value, namely
during encoding errors when converting wchars to multi-byte characters.
This would then wreak havoc in the arithmetics we do following the
vsnprintf() call. However, since we never do any wchar shenanigans in
our code it should never happen.

Let's encode this assumption into the code as an assert(), similarly how
we already do this in other places (like strextendf_with_separator()).
src/basic/strxcpyx.c