]> OCCT Git - occt.git/commitdiff
0031010: Foundation Classes - heap-buffer-overflow reported by Clang address sanitize...
authorabv <abv@opencascade.com>
Mon, 30 Sep 2019 18:37:55 +0000 (21:37 +0300)
committerabv <abv@opencascade.com>
Sat, 19 Oct 2019 09:31:36 +0000 (12:31 +0300)
Use of memcmp is replaced by strncmp to avoid possible read access out of string buffer size

src/OSD/OSD_Path.hxx

index 163c80487b65061d31e044c31779fcbe43027a01..397666bd63f7348652c88cea0581d91626e168f4 100644 (file)
@@ -228,7 +228,10 @@ public:
   //!   \\?\D:\very long path
   //! File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix.
   //! @return true if extended-length NT path syntax detected.
-  static Standard_Boolean IsNtExtendedPath (const char* thePath) { return ::memcmp (thePath, "\\\\?\\", 4) == 0; }
+  static Standard_Boolean IsNtExtendedPath (const char* thePath) 
+  { 
+    return ::strncmp (thePath, "\\\\?\\", 4) == 0;
+  }
 
   //! UNC is a naming convention used primarily to specify and map network drives in Microsoft Windows.
   //! Sample path:
@@ -236,31 +239,40 @@ public:
   //! @return true if UNC path syntax detected.
   static Standard_Boolean IsUncPath (const char* thePath)
   {
-    if (::memcmp (thePath, "\\\\", 2) == 0)
+    if (::strncmp (thePath, "\\\\", 2) == 0)
     {
       return thePath[2] != '?'
           || IsUncExtendedPath (thePath);
     }
-    return ::memcmp (thePath, "//",   2) == 0;
+    return ::strncmp (thePath, "//", 2) == 0;
   }
 
   //! Detect extended-length UNC path.
   //! Sample path:
   //!   \\?\UNC\server\share
   //! @return true if extended-length UNC path syntax detected.
-  static Standard_Boolean IsUncExtendedPath (const char* thePath) { return ::memcmp (thePath, "\\\\?\\UNC\\", 8) == 0; }
+  static Standard_Boolean IsUncExtendedPath (const char* thePath) 
+  { 
+    return ::strncmp (thePath, "\\\\?\\UNC\\", 8) == 0;
+  }
 
   //! Detect absolute UNIX-path.
   //! Sample path:
   //!   /media/cdrom/file
   //! @return true if UNIX path syntax detected.
-  static Standard_Boolean IsUnixPath (const char* thePath) { return thePath[0] == '/' && thePath[1] != '/'; }
+  static Standard_Boolean IsUnixPath (const char* thePath)
+  {
+    return thePath[0] == '/' && thePath[1] != '/';
+  }
 
   //! Detect special URLs on Android platform.
   //! Sample path:
   //!   content://filename
   //! @return true if content path syntax detected
-  static Standard_Boolean IsContentProtocolPath (const char* thePath) { return ::memcmp (thePath, "content://", 10) == 0; }
+  static Standard_Boolean IsContentProtocolPath (const char* thePath)
+  {
+    return ::strncmp (thePath, "content://", 10) == 0;
+  }
 
   //! Detect remote protocol path (http / ftp / ...).
   //! Actually shouldn't be remote...