]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Avoid array-bounds error when debug/fortify enabled
authorDerrick Lyndon Pallas <derrick@argosylabs.com>
Mon, 22 Apr 2019 20:19:14 +0000 (20:19 +0000)
committerChang, Harry <harry.chang@intel.com>
Tue, 13 Aug 2019 06:49:07 +0000 (14:49 +0800)
This code causes GCC to error out due to a bounds error with the following set

-D_GLIBCXX_DEBUG
-D_FORTIFY_SOURCE=2

The solution is to copy via iterator.

util/expression_path.h

index 3075b4d42ca70ae1a632c970d657d0890bcfceeb..ac4ca97dae6f5810a3b7e5245c5149d5cf0e24a0 100644 (file)
@@ -56,9 +56,8 @@ std::string inferExpressionPath(const std::string &sigFile) {
     // POSIX variant.
 
     // dirname() may modify its argument, so we must make a copy.
-    std::vector<char> path(sigFile.size() + 1);
-    memcpy(path.data(), sigFile.c_str(), sigFile.size());
-    path[sigFile.size()] = 0; // ensure null termination.
+    std::vector<char> path(sigFile.begin(), sigFile.end());
+    path.push_back(0); // ensure null termination.
 
     std::string rv = dirname(path.data());
 #else