From f6b0130cbdb0ad403daee47de5ce81acf0c77073 Mon Sep 17 00:00:00 2001
From: Ahmad Samir <a.samirh78@gmail.com>
Date: Wed, 30 Apr 2025 16:34:44 +0300
Subject: [PATCH] QSslCertificate: fromPath(): check the path arg isn't empty

`path` may contain wildcard glob patterns or regular expression ones,
so this method tries to get a path prefix without those special
characters, but that prefix could end up being empty, to counter
that, "." is used as a prefix. This led to iterating over the
current dir, which isn't the intended behavior. If the current dir
has many files, this could end up slowing things down (which is what
happens in the bug report).

Fix the issue by returning early if `path` is empty.

Amends 49f143e19ca11ef48260a3aaaa4ddbe490cf81ab.

[ChangeLog][QtNetwork][QSslCertificate][Important Behavior Changes]
fromPath() no longer accepts an empty path, which would previously
result in searching the current directory.

Fixes: QTBUG-134419
Change-Id: I29224c3a47794b4095db5feae32a964dd9b854ff
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 2875c4358beedd0997b60d21df4b95dbfec4f9a6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 23d3d83061dda788a67f18264f27e5ac500006db)
(cherry picked from commit cb319e88e7119259fcfc11f64bc7912191b3c195)
---

diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 2aa2430..3fa5a19 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -616,6 +616,9 @@
                                                  QSsl::EncodingFormat format,
                                                  PatternSyntax syntax)
 {
+    if (path.isEmpty())
+        return {};
+
     // $, (,), *, +, ., ?, [, ,], ^, {, | and }.
 
     // make sure to use the same path separators on Windows and Unix like systems.
