Pārlūkot izejas kodu

Merge pull request #13568 from ghalliday/issue23804

HPCC-23804 Fix potential memory corruption using forward modules

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 5 gadi atpakaļ
vecāks
revīzija
07c7dadcb1
3 mainītis faili ar 4 papildinājumiem un 0 dzēšanām
  1. 1 0
      ecl/hql/hqlexpr.hpp
  2. 1 0
      ecl/hql/hqlgram.hpp
  3. 2 0
      ecl/hql/hqlgram2.cpp

+ 1 - 0
ecl/hql/hqlexpr.hpp

@@ -995,6 +995,7 @@ public:
     }
     ~HqlLookupContext();
 
+    void clearParentContainer() { container = nullptr; }
     void noteBeginAttribute(IHqlScope * scope, IFileContents * contents, IIdAtom * name);
     void noteBeginModule(IHqlScope * scope, IFileContents * contents);
     void noteBeginQuery(IHqlScope * scope, IFileContents * contents);

+ 1 - 0
ecl/hql/hqlgram.hpp

@@ -387,6 +387,7 @@ public:
     {
     }
     bool hasAnyActiveParameters();
+    void clearParentContainer() { lookupCtx.clearParentContainer(); }
 public:
     CIArrayOf<ActiveScopeInfo> defineScopes;
     HqlScopeArray defaultScopes;

+ 2 - 0
ecl/hql/hqlgram2.cpp

@@ -3220,6 +3220,8 @@ void HqlGram::processForwardModuleDefinition(const attribute & errpos)
     }
 
     HqlGramCtx * parentCtx = new HqlGramCtx(lookupCtx, inSignedModule);
+    // since the forward scope lives longer than this HqlGram clear the container to prevent access to invalid memory
+    parentCtx->clearParentContainer();
     saveContext(*parentCtx, true);
     Owned<IHqlScope> newScope = createForwardScope(queryGlobalScope(), parentCtx, lookupCtx.queryParseContext());
     IHqlExpression * newScopeExpr = queryExpression(newScope);