浏览代码

HPCC-17249 Various small ptree fixes

1) Name given to addPropTree could be invalided whilst adding, if name ptr was
reference to name in node being added.
2) Guard against removeProp(X[0]), which could cause crash in Dali.

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith 8 年之前
父节点
当前提交
b36ecc5ffb
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8 3
      system/jlib/jptree.cpp

+ 8 - 3
system/jlib/jptree.cpp

@@ -1794,7 +1794,13 @@ IPropertyTree *PTree::addPropTree(const char *xpath, IPropertyTree *val)
                 IPropertyTree *_val = ownPTree(val);
                 dbgassertex(QUERYINTERFACE(_val, PTree));
                 PTree *__val = static_cast<PTree *>(_val);
+
+                /* NB: potentially param xpath is a reference to the existing name.
+                 * So fetch new name ptr after set.
+                 */
                 __val->setName(xpath);
+                xpath = __val->queryName();
+
                 addingNewElement(*_val, -1);
                 if (checkChildren())
                 {
@@ -1976,7 +1982,7 @@ bool PTree::removeProp(const char *xpath)
                     {
                         StringAttr digit(digitStart, xxpath-digitStart);
                         unsigned i = atoi(digit);
-                        if (i <= child->value->elements())
+                        if (i && i <= child->value->elements())
                         {
                             removingElement(child->value->queryElement(i-1), i-1);
                             child->value->removeElement(i-1);
@@ -2731,8 +2737,7 @@ void PTree::clone(IPropertyTree &srcTree, IPropertyTree &dstTree, bool sub)
             {
                 IPropertyTree &child = iter->query();
                 IPropertyTree *newChild = clone(child, false, sub);
-                StringAttr name(newChild->queryName());
-                dstTree.addPropTree(name, newChild);
+                dstTree.addPropTree(newChild->queryName(), newChild);
             }
             while (iter->next());
         }