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

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