From 4cae4a0de5e5288e706864e7455e599586cce9a5 Mon Sep 17 00:00:00 2001 From: wangkx Date: Mon, 22 Jan 2024 17:13:34 -0500 Subject: [PATCH] HPCC-29679 Fix isPathInPlane issue when similar prefixes The existing isPathInPlane() uses the startsWith() to check whether a path is a plane path or not. It may return a wrong result when 2 planes have similar path prefixes (ex. /abcd and /abc). Revise based on review: return false if prefix is empty/path is not Signed-off-by: wangkx --- dali/base/dautils.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dali/base/dautils.cpp b/dali/base/dautils.cpp index cfdd1fc3ba1..3532f4c575f 100644 --- a/dali/base/dautils.cpp +++ b/dali/base/dautils.cpp @@ -119,7 +119,28 @@ IPropertyTree * getDropZonePlane(const char * name) bool isPathInPlane(IPropertyTree *plane, const char *path) { - return isEmptyString(path) || startsWith(path, plane->queryProp("@prefix")); + if (isEmptyString(path)) + return true; + + const char *prefix = plane->queryProp("@prefix"); + if (isEmptyString(prefix)) + return false; //prefix is empty, path is not - can't match. + + while (*prefix && *prefix == *path) + { + path++; + prefix++; + } + if (0 == *prefix) + { + if (0 == *path || isPathSepChar(*path)) + return true; + if (isPathSepChar(*(path - 1))) //implies both last characters of prefix and path were '/' + return true; + } + else if (0 == *path && isPathSepChar(*prefix) && (0 == *(prefix + 1))) + return true; + return false; } bool validateDropZone(IPropertyTree * plane, const char * path, const char * host, bool ipMatch)