diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-07-18 11:16:41 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-07-21 01:26:13 +0200 |
| commit | d5ef3f53168ca39d317e3ecb9793988cfba50f7b (patch) | |
| tree | 240569f7e190c04d30ae6ff8e304f8c9636a47a8 /src/corelib/kernel/qmetaobject.cpp | |
| parent | 53f2a8159f595f6116d86fced53b3c36ebd5293d (diff) | |
QTextStreamPrivate: fix a particularly nasty Bool Trap
The bool number = false parameter of putString() overloads is not only
a classical Bool Trap (ie. doesn't give any hint to the reader of a
call what 'true' or 'false' means), it also, in combination with the
(ptr, n, bool=false) and (view, bool=false) overloading may cause a
(ptr, n) argument list to accidentally match (view, number) instead:
if decltype(ptr) isn't (const) QChar*, but one of the views accepts
the type in it's (Char*) ctor, the call might be solved as (View(ptr),
bool number(n)).
This is not acceptable for a security-critical component.
To fix, introduce a strong enum, PutStringMode { String, Number } to
replace the bool. Only after this change it is safe to remove the
(unused) (ptr, n, bool) overload, for the above-mentioned reason, so
do it now.
The alternative was to split putString() into putString() and
putNumber(), but there's already a putNumber(qulonglong, bool
negative), so I opted for an enum argument instead.
Fixes: QTBUG-138520
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I78d1a9132d5ef41e33b9462d48d2f41401e1f688
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
0 files changed, 0 insertions, 0 deletions
