diff options
author | Marc Mutz <[email protected]> | 2025-08-01 11:48:57 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2025-08-20 19:05:56 +0000 |
commit | 9ad39d7c9ac5658f834f9a1077386a52e223e949 (patch) | |
tree | 10594602b786fd23227d591af46efb0b3550f108 /src/tools/windeployqt/utils.cpp | |
parent | 1af8d03845e84c9bca771facf958d545555042dd (diff) |
qvsnprintf: fail if the result size doesn't fit into an int6.9
The old code silently truncated the return value of the fallback
implementation. This is dangerous, as the caller might rely on the
truncated value to confirm that everything was written when it
actually wasn't, incl. trusting the return value to allocate a buffer
of a size dependent on the result and then strcpy()ing the data over
(which would overflow the target buffer, since the NUL byte is
actually at `n` and not at `result`, as the function post-condition
would require for a result < n.
POSIX specifies¹ that errno be set to EOVERFLOW and -1 be returned, so
do that.
As a drive-by, replace use of qMin() with std::min() (which statically
asserts that both arguments are of the same type, unlike qMin(), which
performs integral promotion on the arguments).
Use qt_saturate() for now, because 6.5 doesn't have
q26::saturate_cast(). A follow-up patch will clean this up for
6.8...dev.
[ChangeLog][QtCore][q(v)snprintf] Fixed a bug that would cause
q(v)snprintf() to report success on some platforms, even though the
result was truncated.
Amends the port of Qt containers from int to qsizetype. Didn't check
for a particular commit, because a) it's probably several that apply
and b) they are so much older than the currently active branches that
I didn't feel I need to be more specific than, essentially, "Qt 6.0".
¹ https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html
Fixes: QTBUG-138860
Pick-to: 6.8 6.5
Change-Id: I6de8a99c238539a535462e964a0645bd0c704fff
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Mårten Nordheim <[email protected]>
(cherry picked from commit ed3589374523ea5cef3ff572eab94a137629025c)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 37950e7d3504a34a30f1f6622bacb6f3777fdd57)
Diffstat (limited to 'src/tools/windeployqt/utils.cpp')
0 files changed, 0 insertions, 0 deletions