Blame SOURCES/0005-Scanner-Avoid-accessing-dangling-pointers-in-destroy.patch

b814f0
From e5c272423d1bba2825086b82fd97499237a6fa4b Mon Sep 17 00:00:00 2001
b814f0
From: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
b814f0
Date: Fri, 30 Oct 2020 16:55:30 +0200
b814f0
Subject: [PATCH 05/52] Scanner: Avoid accessing dangling pointers in
b814f0
 destroy_func()
b814f0
b814f0
Usually, the object associated with the resource gets destroyed in the
b814f0
destroy_resource() function.
b814f0
b814f0
Therefore, we need to double-check that the object is still alive before
b814f0
trying to reset its m_resource.
b814f0
b814f0
Change-Id: I26408228f58919db17eb29584a1cbd4a9427d25c
b814f0
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
b814f0
(cherry picked from commit 735164b5c2a2637a8d53a8803a2401e4ef477ff0)
b814f0
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
b814f0
---
b814f0
 src/qtwaylandscanner/qtwaylandscanner.cpp | 4 +++-
b814f0
 1 file changed, 3 insertions(+), 1 deletion(-)
b814f0
b814f0
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp
b814f0
index 1d635f06..e2f87bbd 100644
b814f0
--- a/src/qtwaylandscanner/qtwaylandscanner.cpp
b814f0
+++ b/src/qtwaylandscanner/qtwaylandscanner.cpp
b814f0
@@ -814,7 +814,9 @@ bool Scanner::process()
b814f0
             printf("        if (Q_LIKELY(that)) {\n");
b814f0
             printf("            that->m_resource_map.remove(resource->client(), resource);\n");
b814f0
             printf("            that->%s_destroy_resource(resource);\n", interfaceNameStripped);
b814f0
-            printf("            if (that->m_resource == resource)\n");
b814f0
+            printf("\n");
b814f0
+            printf("            that = resource->%s_object;\n", interfaceNameStripped);
b814f0
+            printf("            if (that && that->m_resource == resource)\n");
b814f0
             printf("                that->m_resource = nullptr;\n");
b814f0
             printf("        }\n");
b814f0
             printf("        delete resource;\n");
b814f0
-- 
b814f0
2.35.1
b814f0