This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new 400e2aaef84 Fix potential use-after-free of viewQuery in 
ExecRefreshMatView (#1159)
400e2aaef84 is described below

commit 400e2aaef84d7aa8668e5a87f1a103664acec3bf
Author: Jianghua.yjh <[email protected]>
AuthorDate: Tue Jun 17 07:59:43 2025 -0700

    Fix potential use-after-free of viewQuery in ExecRefreshMatView (#1159)
    
    In ExecRefreshMatView(), the pointer viewQuery may be invalidated when
    make_new_heap_with_colname() closes the old heap via table_close(OldHeap, 
NoLock).
    This happens because table_close() can release relcache entries and 
associated
    rules, including rd_rules, which stores the viewQuery.
    
    To avoid accessing a possibly freed memory region, make a deep copy of
    viewQuery before invoking make_new_heap_with_colname(), and use this copy
    as dataQuery for further processing.
    
    Fix: ERROR:  unrecognized node type: 2139062143 (copyfuncs.c:7663)
    
    Author: Jianghua Yang
---
 src/backend/commands/matview.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index e56e9d76fb9..ea3408654c2 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -463,7 +463,8 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char 
*queryString,
        if (!stmt->skipData && RelationIsIVM(matviewRel))
                dataQuery = rewriteQueryForIMMV(viewQuery,NIL);
        else
-               dataQuery = viewQuery;
+               /* viewQuery maybe released in make_new_heap_with_colname. */
+               dataQuery = copyObject(viewQuery);
 
        /*
         * Check that there is a unique index with no WHERE clause on one or 
more


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to