Skip to content

Commit

Permalink
HPCC-29679 Fix isPathInPlane issue when similar prefixes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wangkx committed Jan 29, 2024
1 parent d5e95c7 commit 4cae4a0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion dali/base/dautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4cae4a0

Please sign in to comment.