Browse Source

HPCC-24085 Path names used to create manifest resource tags are not being normalized

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 5 years ago
parent
commit
a38f63da17
2 changed files with 31 additions and 1 deletions
  1. 28 1
      system/jlib/jfile.cpp
  2. 3 0
      system/jlib/jfile.hpp

+ 28 - 1
system/jlib/jfile.cpp

@@ -5126,9 +5126,36 @@ bool isAbsolutePath(const char *path)
     }
 }
 
+//Treat a filename as remote if:
+//  a) The filename begins \\ or //
+//  b) The filename begins xxx://
+//
+bool isRemotePath(const char *path)
+{
+    if (!path||!*path)
+        return false;
+    if (isPathSepChar(path[0]) && isPathSepChar(path[1]))
+        return true;
+
+    const char * cur = path;
+    for (;;)
+    {
+        switch (*cur++)
+        {
+        case '/':
+        case '\\':
+        case '\0':
+            return false;
+        case ':':
+            return cur[0]=='/' && cur[1]=='/';
+        }
+    }
+}
+
 StringBuffer &makeAbsolutePath(const char *relpath,StringBuffer &out, bool mustExist)
 {
-    if (isAbsolutePath(relpath))
+    // NOTE - this function also normalizes the supplied path to remove . and .. references
+    if (isRemotePath(relpath))
     {
         if (mustExist)
         {

+ 3 - 0
system/jlib/jfile.hpp

@@ -539,7 +539,10 @@ inline const char *splitDirTail(const char *path,StringBuffer &dir)
     return tail;        
 }
 
+extern jlib_decl bool isRemotePath(const char *path);
 extern jlib_decl bool isAbsolutePath(const char *path);
+
+// NOTE - makeAbsolutePath also normalizes the supplied path to remove . and .. references
 extern jlib_decl StringBuffer &makeAbsolutePath(const char *relpath,StringBuffer &out,bool mustExist=false);
 extern jlib_decl StringBuffer &makeAbsolutePath(StringBuffer &relpath,bool mustExist=false);
 extern jlib_decl StringBuffer &makeAbsolutePath(const char *relpath, const char *basedir, StringBuffer &out);