Commit Graph

61409 Commits

Author SHA1 Message Date
Thiago Macieira
fb40737b0d QProcess/Unix: improve the error message if the child modifier throws
Functionality added for 6.5, but after translatable string freeze.

Change-Id: Icfe44ecf285a480fafe4fffd174d984c5349e0cb
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 19:10:03 +02:00
Thiago Macieira
ba05af82d3 QProcess/Unix: protect against stack unwinding in the child process stub
There are two types of stack unwinding that can happen on Unix systems:
C++ exceptions and PThread cancellations (on some systems, like Linux,
PThread cancellations can be caught in catch(...) statements). We call a
variety of PThread cancellation functions from inside the child stub,
like close(). To avoid problems, we disable PThread cancellations
completely before fork() or vfork().

The C++ exception case is simpler, because we can be sure of catching
them with the catch (...) statement and simply transform them into an
error message. This is also testable, which the PThread cancellation
isn't.

The error message isn't ideal because we're string-frozen. I'll improve
it for 6.6.

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d97a475c93ff1
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 10:10:03 -07:00
Ahmad Samir
d2242c353f MOC: pass the erroneous Symbol as an arg to Parser::error() overload
We already know the Symbol while parsing, passing a reference to it to
error() makes it simpler to construct the error message.

This fixes an issue where reporting an error about "NONSENSE" in e.g.:
Q_PROPERTY(Foo* foo NONSENSE foo)

would be off-by-one and the error message would say:
path/to/file.h:11:1: error: Parse error at "foo"

instead of 'at "NONSENSE"', which is where the parser actually found an
unexpected attribute.

Fixes: QTBUG-36367
Pick-to: 6.5
Change-Id: Ief70e544af41f7575fbeea9b936fa8197c3ef43d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-15 19:20:21 +03:00
Volker Hilsheimer
328680b34b Update screenshot example
Refresh screenshot of the example, and remove "Example" word from title.

Pick-to: 6.5
Change-Id: I88c00db5b25536c45622bc580a9da5aaf01610bc
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-05-15 18:20:21 +02:00
Tor Arne Vestbø
6a28b391f7 Don't grab QWhatsThis background on non-Windows platforms
The logic was introduced in 186589abd48b17fdb9b631211008753e2d1701b3
due to Windows supposedly not supporting NoSystemBackground. It's
not clear whether this is still the case, but as this workaround
causes problems on other platforms, such as bringing up the screen
capturing permission dialog on macOS, it should be limited to Windows.

Fixes: QTBUG-113556
Pick-to: 6.5
Change-Id: I197adb5fc177faebc0f2fcd28612e3daa0c22ed5
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 18:20:20 +02:00
Ahmad Samir
c4ce22ef24 QEventDispatcher/WASM: fix a lambda name
It's returning milliseconds not nanoseconds.

Change-Id: I7dbc3f4043694b6ddf87c6ad9e4d20d3a9af0fd1
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-05-15 17:21:22 +03:00
Edward Welbourne
30b9c3a135 Shrink the CBOR dumper example's image
Apply optipng -o7 -zm9 -strip all to the image to make it more compact.

Change-Id: Iebfc1f767759b5beac47bd7efa61d1c655163f03
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-15 15:51:01 +02:00
Tor Arne Vestbø
08f85c27bb Darwin: Use direct runtime interface to manage autorelease pools
The Objective-C runtime supports autorelease pools via a language
specific ABI supplement, akin to the “Itanium” generic ABI for C++.

 https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support

These interfaces are used by NSAutoreleasePool internally, as well as
inserted by the compiler when using the @autoreleasepool syntax in
Objective-C code.

We have our own wrapper, QMacAutoReleasePool, which allows us to
set up pools in C++ code as well. We now use these lower level
interfaces in the implementation, instead of NSAutoreleasePool,
as this reduces overhead due to not needing to allocate and destroy
a NSAutoreleasePool.

This also opens up the possibility of using Automatic Reference Counting
(ARC) in Qt down the road, as explicit NSAutoreleasePool usage is forbidden
in that mode (while @autoreleasepool is not, and uses the runtime ABI
internally as before).

Change-Id: I06fdb4a24ae4972820f866e0a129a1b355bc8a6b
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-15 15:51:01 +02:00
Tor Arne Vestbø
7cf7e88417 Darwin: Disable QMacAutoReleasePool tracker unless explicitly enabled
There's a few orders of magnitude of overhead using QMacAutoReleasePool
with the tracker enabled, so disable it even for debug builds, unless
explicit auto release pool debugging has been enabled via the environment
variable QT_DARWIN_DEBUG_AUTORELEASEPOOLS.

Pick-to: 6.5
Change-Id: Iec00c703eb21e1914903954cfd02f9f6b1ec2a1f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-05-15 15:51:00 +02:00
Tor Arne Vestbø
59c686080d Darwin: Disable QMacAutoReleasePool tracker in release builds
It adds overhead that is noticeable, especially in tight loops that
rely on an auto-release pool. For example, this improves the QLocale
date to string transformations an order of a magnitude.

Task-number: QTBUG-104785
Pick-to: 6.5
Change-Id: I246dc4e114bd75dd4e3e9e42b061c4c20c94d522
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-15 15:51:00 +02:00
Tor Arne Vestbø
e95f03f989 Darwin: Remove QMacAutoReleasePool heap allocation detection
This is handled by the Objective-C runtime nowadays, where it will
abort if the situation is detected, with the option to break on
objc_autoreleasePoolInvalid to debug the situation.

Pick-to: 6.5
Change-Id: Idf2c4aacc77e41a3deebf270303f4f13cfb0819b
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-05-15 13:51:00 +00:00
Volker Hilsheimer
f4b338833e Move the addressbook tutorial into manual tests
The tutorial is building an elaborate UI around a QMap. It doesn't use
structured data, and it doesn't use model/view (which the dedicated
addressbook example in itemviews does).

It's not a good way of building an application, and the individual APIs
for creating layouts, dialogs, or import/export are explained well
enough in other examples.

Pick-to: 6.5
Change-Id: Iffe47a0f6e04a933edb917c877ae845f50b74b4a
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-05-15 14:52:17 +02:00
Ievgenii Meshcheriakov
a035e8b768 QDBusMetaObjectGenerator: Use uniform loops to iterate over methods
Use the same structure for iterating over signals and other
methods in 3 places. Introduce MethodMap type alias to make
types shorter.

Change-Id: I732b582fc8c47616037087b77a79eb13ecf17019
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 14:02:47 +02:00
Ievgenii Meshcheriakov
0f37c47713 QtDBus: Convert some loops to ranged for loops
Convert some loops that are using Java-style iterators into
ranged for loops for better readability.

Change-Id: I14f6339608d201fe06a753be236db52815cbf5c4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 14:02:47 +02:00
Edward Welbourne
4768fcf836 Fix case-sensitivity of exponent separator check in Cyrillic fall-back
When matching the locale's correct exponent separator, QLocale was
doing a case-insensitive match; but the Cyrillic fall-back was
matching case-sensitively, so failed to catch the case of lower-case e
and its Cyrillic equivalent, when used in a Cyrillic font in place of
the upper-case form of the other, where that's the locale's official
separator. So make this comparison case-insensitive.

Added some test-cases for the lower-case exponential separator.

Pick-to: 6.5
Fixes: QTBUG-113443
Change-Id: I18e22d7b3451fbb61e87d5b93661eadff3c7356e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-05-15 14:02:47 +02:00
Edward Welbourne
637e1542cf rsslisting example: fix bug in construction of title string
The correct time to clear titleString and linkString is at the start
of the item element, to avoid not only the left-overs from a previous
item but also any stray titles and links that don't belong to any
item. The channel element, that contains the items, may also have
title and link elements. This, indeed, lead to the first entry in the
displayed table having a "Qt Blog" prefix on its blog-post's title.

Fortunately the link was already being set, usually to empty, due to
the lack of rss:about attributes on item elements.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I16647e2498b58caaafa6e88ef73f0d934a1f8396
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-05-15 14:02:46 +02:00
Edward Welbourne
fb2d4074c1 rsslisting example: shuffle parts of constructor for clarity
Group related things together, improve the logical flow of the code.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: If3eb577b74128b305ca5fb3074168280ec2d4db8
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-05-15 14:02:46 +02:00
Edward Welbourne
233ca06500 rsslisting example: move default URL to main()
It felt more natural that the RSSListing class would be agnostic about
the default URL, so let it be a constructor parameter. In the process,
update the URL to what the old one now redirects to (thanks to Ivan
Solovev for spotting that) and make the constructor explcit (thaks to
Ievgenii Meshcheriakov for suggesting this).

Task-number: QTBUG-111228
Pick-to: 6.5
Change-Id: I9f4c0d126e0872bb4ec6e6bb41add7e9d2a9537f
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-05-15 14:02:45 +02:00
Edward Welbourne
3cdc65c2ec rsslisting example: Tidy up #include usage
Replace one #include with a forward-declaration - in rsslisting.h QUrl
is only passed by reference to a function. Shuffle order of existing
forward declarations to be alphabetic, in the process.

Shuffle #include order in sources so that this example's own headers
appear before the Qt ones.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I69a9e091c77f9d3190c0217c8bd9262e056f66fc
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2023-05-15 14:02:45 +02:00
Edward Welbourne
00ccc56434 rsslisting example (coding style): split a long line, purge stray braces
Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: Ic919d4dee74823f11c55d286beba447d45111754
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-05-15 14:02:45 +02:00
Edward Welbourne
f8ad9cd23c rsslisting example (coding style): fix horizontal spacing
Remove space after *, insert space after comma.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I7525715dede20b45241efaf3f9540c896b1455c7
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-05-15 14:02:44 +02:00
Edward Welbourne
d52cc4725f rsslisting example: remove unused include and surplus blank lines
Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: Ibfa82aef67eaf6ba758dade30a4c9542f2836123
Reviewed-by: Mate Barany <mate.barany@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-05-15 14:02:44 +02:00
Edward Welbourne
7337474d04 Convert remaining QT_NO_XMLSTREAM* to use feature system
Replace the check in qxmlstream.h with a QT_REQUIRE_CONFIG since the
code that includes this header does no checking, whether on the define
or the feature, so is better off getting told about the missing
feature at the point of include than complaining about an undefined
type despite its header being overtly included.

For the rest, just do the usual transformation to QT_CONFIG(),
flipping the ones that were #ifdef rather than #ifndef, so the
condition is positive. Shifted a couple of open-braces of classes to
the next line, where they belong, in the process.

Change-Id: If9c496082f0489b0f9f4070364cbf840e603fce1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-15 14:02:43 +02:00
Edward Welbourne
526ce669ed Clean up phrasing of --help-all and other help options
The options included by --help-all, although they are "specific to
Qt", are "specific" to all Qt applications, so - in the present
context, of QCommandLineParser - not specific at all. It's the options
described by -h that are specific, to the present command; the Qt
options are generic (in the present context).

So rework the help string for --help-all itself and the documentation
of the function. It had, in any case, an overly-complex first line,
that descended into too much detail. Updated test to match.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I06da0af41be60e6e1b7616984001ddb9ca33aad6
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
2023-05-15 14:02:43 +02:00
Edward Welbourne
56df9e5603 savegame example: clarify that CBOR can be read
The documentation talked about using CBOR to keep folk from reading,
where (of course) it merely makes it more obscure (and compact). Make
clear that this just makes it less easy and mention the tool that
makes it easy again.

Task-number: QTBUG-111228
Pick-to: 6.5
Change-Id: I472acda4b7533db41ab0e78b694e0256b34d2b40
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-15 14:02:42 +02:00
Edward Welbourne
1371cd107a Add metadata to serialization examples
There's no separate category for {de,}serialization, so I've put them
in Input/Output; and at least some of them are relevant to
transmission over the network, so include that as a tag, so that
someone writing a network application that wants to use what they
illustrate gets a chance of being lead to it.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: Ie9f6dbaf85aed852e9f64eba05ec8c5fe0a7382d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-05-15 14:02:42 +02:00
Andreas Buhr
ae34a78b24 Don't create a QTimeZonePrivate object for an unsupported time zone ID
The QTzTimeZoneCache created one cache entry for every time zone
which was looked up, even if the code was invalid. This uses some
memory for each time zone code queried and thus allows DOS attacks
if user supplied time zone codes are parsed.
This patch prevents the creation of QTimeZonePrivate objects for
invalid time zone IDs.

Change-Id: I22007f6681bea54fa08639f4f786e1a49d10f920
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 14:02:42 +02:00
Edward Welbourne
13e8609fc9 Include all available IANA DB zones for the TZ backend
Previously, QTzTimeZonePrivate::availableTimeZoneIds() only reported
the zones listed in the zone.tab file, which maps territories to
zones. It thus omitted several zones that are provided by the IANA DB,
but not the primary zones for any territory. This meant that it was
possible to pass a zone name to the constructor successfully, despite
isTimeZoneIdAvailable() claiming it isn't available.

Pick-to: 6.5
Change-Id: I9e4eb7f4cfe578204951b995f0ad9ffd7eed5f9c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 14:02:41 +02:00
Edward Welbourne
06e2719f73 Add test-cases for QDate::{start,end}OfDay() at QDateTime's bounds
Task-number: QTBUG-68855
Change-Id: Ic91cb5f9947ce5ee533fc77ae24a50376e139ab3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 14:02:41 +02:00
Edward Welbourne
eff0ffbd1b Sanitize the handling of limitations of the MS time-zone backend
tst_QDate::startOfDay_endOfDay() and its _data() were in danger of
growing a lot of ugly #if-ery to work round the known limitations of
MS's time-zone API and the backend built on them. Replace the #if-ery
with a flags enum indicating which parts we need to ignore on MS and
limit the #if-ery to how those flags get exercised.

Change-Id: I8657b4fba75f1aef1f3f9374e05f60354dc25e34
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-15 14:02:40 +02:00
Topi Reinio
cb8a71dac6 Doc: Replace mentions of deprecated macro
Q_ENUMS() is deprecated in favor of Q_ENUM().

Pick-to: 6.5
Task-number: QTBUG-113229
Change-Id: I29cc23c87b1d6e8eeb49dd1d3ddaf4ca7d2cf8c2
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2023-05-15 08:57:02 +00:00
Topi Reinio
506d237751 Doc: Make QByteArray(qsizetype size, Qt::Initialization) doc public
The constructor that doesn't explicitly initialize the content of the
array can be useful in some cases.

Pick-to: 6.5
Fixes: QTBUG-111582
Change-Id: Icc4bd753f1944a91be70316a7303bb822f79d472
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-05-15 08:56:21 +00:00
Yuhang Zhao
b5d874e36f Fix the QT_REQUIRE_VERSION macro
Rewrite the whole macro as a function and use QVersionNumber instead
of manual parsing to make it more modern and more readable.

Change-Id: I25498320ef6cd9f19be9267421e2727cd28cfd7c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-05-15 08:47:17 +00:00
Thiago Macieira
9a73bc5f3d QDnsLookup/Windows: use DnsQueryEx so IPv6 servers are supported
Similar test with link-local server on the same network:

$ $objdir/tests/manual/qdnslookup/qdnslookup.exe @fe80::1e1b:dff:fee2:49e6%Ethernet
; <<>> QDnsLookup 6.6.0 <<>> qdnslookup @fe80::1e1b:dff:fee2:49e6%Ethernet
;; status: NoError
;; QUESTION:
;qt-project.org                 IN A

;; ANSWER:
qt-project.org            3532  IN A    52.18.144.254

;; Query time: 17 ms
;; SERVER: fe80::1e1b:dff:fee2:49e6%Ethernet#53

Server's dnsmasq log shows it was queried.

We don't know why we must set the port to 0. It works for me the regular
way, but not for everyone who tested this patch.

[ChangeLog][QtNetwork][QDnsLookup] setNameserver() now supports IPv6
servers with on Apple systems, AIX, FreeBSD, NetBSD, Solaris, and
Windows.

(AIX, NetBSD and Solaris not directly tested, but their docs online show
they have res_setservers())

Change-Id: I3e3bfef633af4130a03afffd175d5bfd4e7922b9
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-14 21:44:21 -07:00
Thiago Macieira
678964b242 QDnsLookup/Unix: add support for res_setservers()
This API is found on FreeBSD, Darwin, Solaris, AIX, and Android Bionic.
That means we complement IPv6 support for most platforms.

Test on macOS:

$ $objdir/tests/manual/qdnslookup/qdnslookup @fe80::1e1b:dff:fee2:49e6%en0
; <<>> QDnsLookup 6.6.0
;; status: NoError
;; QUESTION:
;qt-project.org                 IN A

;; ANSWER:
qt-project.org            3336  IN A    52.18.144.254

;; Query time: 2 ms
;; SERVER: fe80::1e1b:dff:fee2:49e6%en0#53

Dnsmasq log on the server confirms it was queried.

Change-Id: I3e3bfef633af4130a03afffd175d59c67faa463f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-14 21:44:20 -07:00
Thiago Macieira
eb9f88a078 QDnsLookup/Unix: modernize the setting of IPv6 server addresses
Instead of using #if, this now uses SFINAE to detect the presence of the
glibc extensions to set IPv6 nameserver addresses. It's also possible
that this fixes some bugs that have always been there, but never checked
because we don't have a way to unit-test explicit name servers.

To that effect, this commit adds a manual unit test that mimics the BIND
tool "dig". When running:

 ./qdnslookup qt-project.org any @dns.google

it printed for me:

; <<>> QDnsLookup 6.6.0
;; status: NoError
;; QUESTION:
;qt-project.org                 IN ANY

;; ANSWER:
qt-project.org            3600  IN MX   10 mx.qt-project.org
qt-project.org            3600  IN NS   ns14.cloudns.net
qt-project.org            3600  IN NS   ns11.cloudns.net
qt-project.org            3600  IN NS   ns12.cloudns.net
qt-project.org            3600  IN NS   ns13.cloudns.net
qt-project.org            3600  IN A    52.18.144.254
qt-project.org            3600  IN TXT  "v=spf1 mx ip4:193.209.87.4 include:spf.protection.outlook.com ~all"

;; Query time: 241 ms
;; SERVER: 2001:4860:4860::8844#53

strace confirms the DNS queries were sent to the correct address.

Change-Id: I3e3bfef633af4130a03afffd175d56a92371ed16
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-14 21:44:19 -07:00
Thiago Macieira
df2131426e tst_QProcess: move setChildProcessModifier test to a Q_OS_UNIX section
There's no need to say it's getting skipped on Windows. moc *can* parse
the #ifdefs these days.

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d95c709ff6a74
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
2023-05-15 00:12:43 +02:00
Thiago Macieira
49eb9021e3 QProcess/Unix: use open() + fchdir() to change directories
This means we have more system calls (2 more in the parent), but we
can now detect non-existent or inaccessible directories before fork().

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d1003581bff59
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 00:12:43 +02:00
Thiago Macieira
6b561ccf44 QProcess/Unix: use pid_t for the pid
Qt 5 and earlier versions used to share this member with Windows, where
we needed to store a pointer. We had the Q_PID public type, which was
removed in commit b73d5a0511 (6.0). That
commit made the QProcess::processId() public API use qint64, which is
fine. But we don't need to store more bits than the OS actually
requires.

This further reduces QProcessPrivate's size to 688 bytes on 64-bit Unix,
with 5 bytes of tail padding.

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d3fa9345872c0
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
2023-05-15 00:12:41 +02:00
Thiago Macieira
29b2fe40dc Revert commit "don't ever force fork() instead of forkfd()"
This reverts commit d6bf71123d and the
docs from commit 82b75570f0
("QProcess/Linux: fix file descriptor leak in case of failed child
start").

Despite the title of the commit being reverted, the actual consequence
is slightly different: we always use the forkfd() function, but we
change whether we force the use of the fork() library function by use of
the FFD_USE_FORK flag.

Commit 97645478de (5.15) first added the
FFD_USE_FORK flag with a hack to detect whether the setupChild() virtual
might have been overwritten. A configure-time feature to force the flag
was added in commit 2ed99ff5ca (6.0).
Before the 6.0 release, commit d6bf71123d
removed the conditional use of FFD_USE_FORK, with the changelog message
saying "pthread_atfork() callbacks are consistently not invoked".

We've also since added vfork()-like behavior. We tried it for Qt 5.15
and reverted shortly afterwards because we had got the memory semantics
wrong. Commit e1a787a76e (6.5) finally got
it right, for Linux, which revealed another set of problems with
functions used in the child process modifier.

Therefore, we're going to make vfork() and clone() usage opt-in if the
child process modifier is active. This commit is the first part:
disabling their use by default. The flag to opt in will come in Qt 6.6.

[ChangeLog][QtCore][QProcess] Reverted a change from Qt 6.0 that made
the childProcessModifier() callback be run in a child created by means
other than a real fork() library call, a situation in which certain
other library functions would be unusable, unreliable, or cause
deadlocks. A flag to opt in to the solution with better performance will
be added to Qt 6.6.

Task-number: QTBUG-104493
Fixes: QTBUG-111243
Fixes: QTBUG-111964
Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d3e66843e5a29
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-15 00:12:41 +02:00
Thiago Macieira
2b98dd7645 QProcessPrivate: repack and reorganize the members
Reduce the number of #ifdef blocks and use quint8 for the enums that
don't need more than 8 bits anyway (none of them do). Plus move the
std::function callback to an indirect block, as most users of QProcess
won't set them and this type is 4 pointers with libstdc++ and libc++.

After this, QProcessPrivate on 64-bit Unix is 688 bytes, of which:
- 392 bytes from QIODevicePrivate
- 295 bytes of own data
- 3x56 bytes per Channel (which have 5 bytes of tail padding each)
- 1 byte of tail padding and no middle padding

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d188a0821d060
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 00:12:39 +02:00
Thiago Macieira
7dba2c8761 QDnsLookup/Unix: make sure we don't overflow the buffer
The DNS Records are variable length and encode their size in 16 bits
before the Record Data (RDATA). Ensure that both the RDATA and the
Record header fields before it fall inside the buffer we have.

Additionally reject any replies containing more than one query records.

[ChangeLog][QtNetwork][QDnsLookup] Fixed a bug that could cause a buffer
overflow in Unix systems while parsing corrupt, malicious, or truncated
replies.

Pick-to: 5.15 6.2 6.5 6.5.1
Change-Id: I3e3bfef633af4130a03afffd175e4b9547654b95
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2023-05-14 19:47:03 +00:00
Thiago Macieira
0fc0e821f1 QDnsLookup: remove the #if QT_CONFIG(thread) check
There's no fallback anywhere, so this class simply doesn't work if
threading isn't supported. Writing it is an exercise left for whoever
cares for that configuration.

Change-Id: I3e3bfef633af4130a03afffd175e6f68a3f4673f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-14 12:47:01 -07:00
Thiago Macieira
471f134cdd QDnsLookup: remove the explicit metatype registration for the Reply type
It's unnecessary in Qt 6 if we use the new-style connect or if the type
was fully defined in the compilation of the unit containing the moc
output.

Change-Id: I3e3bfef633af4130a03afffd175e6f4e87adf5e1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-13 16:15:02 -07:00
Thiago Macieira
d26709cd8c Network: Remove Q_DECL_METATYPE_EXTERN for single-.cpp metatypes
These were added in commit 20e6a049fe as a
massive sweep of all Q_DECLARE_METATYPE, without thought as to whether
they were actually needed or not. If they are used as a metatype in a
single .cpp file, they don't need to be.

Incidentally removes the entirely incorrect Q_NETWORK_EXPORT of
QDnsLookupReply.

Pick-to: 6.5
Change-Id: I3e3bfef633af4130a03afffd175e6f378f09a3aa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-13 16:15:01 -07:00
Thiago Macieira
c257e518c1 QProcessPrivate: remove the member variable "crashed"
It was only used to later set exitStatus = CrashExit, so simply do it
early.

Drive-by removal of a magic numeric literal in the middle of the source
code. It's still magic, but at least we avoid accidentally making typos.

Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d4176a5d87641
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-13 20:25:27 +00:00
Thiago Macieira
45a03fc506 QNativeSocketEngine: move some code from the _p_p.h to _p.h file
So I can use it in qdnslookup_unix.cpp.

Change-Id: I3e3bfef633af4130a03afffd175d506949968990
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-13 13:24:24 -07:00
Marc Mutz
3b0536bbe8 tst_ContainerApiSymmetry: make assign_impl() robust w.r.t. overallocation
The parameter passed to reserve() is just a hint. The container
implementation is free to choose a larger capacity, and some do
(e.g. QList in prepend optimization mode).

Fix the test by querying the container for its post-make<>()
capacity() and taking a larger-than-expected initial capacity() into
account when later re-checking the capacity().

Change-Id: Id8f26f14e8df9d685ca2387ec4a52d74fea7cb9d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-05-13 16:58:36 +02:00
Marc Mutz
fb58df3260 tst_ContainerApiSymmetry: make a comment more precise
It took me a sec to figure out the relation between the comment and
the code line following it. Make it easier for the next guy and add a
bit more infos.

Amends 7cbdc8abbd.

Change-Id: I4ff2d9a52aef643a92339df32cc86f686a689a9a
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-05-13 16:58:27 +02:00
Marc Mutz
4eea3f857c tst_ContainerApiSymmetry: follow file's style for assign() tests
We use a single line per test slot everywhere else, ignoring even
line-length limitations, to keep the function names aligned for easier
parsing.

Amends 7cbdc8abbd.

Change-Id: Iaf2941aae88392d407d688fc4a7537fcdc0a5851
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-05-13 16:58:19 +02:00