From 4ad36447b211a77f260f163c7acc55174b9c3334 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 26 May 2026 20:49:36 +0900 Subject: [PATCH] Linux: fix CentOS 6 build with GCC 4.4 CentOS 6 builds VeraCrypt with GCC 4.4.7 and -std=c++0x. That compiler does not support range-based for loops, and its libstdc++ does not provide std::string::back() or std::string::pop_back(). Avoid those constructs in the affected Unix/Linux code paths: use VeraCrypt's existing foreach helper when iterating PKCS#11 object handles, and use indexing plus erase() when trimming trailing slashes from PATH entries. This keeps the code valid for newer Linux toolchains while restoring compatibility with the CentOS 6 build environment. --- src/Common/SecurityToken.cpp | 2 +- src/Core/Unix/CoreUnix.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Common/SecurityToken.cpp b/src/Common/SecurityToken.cpp index 79725aad..f45c4cf4 100644 --- a/src/Common/SecurityToken.cpp +++ b/src/Common/SecurityToken.cpp @@ -220,7 +220,7 @@ namespace VeraCrypt throw; } - for(const CK_OBJECT_HANDLE & dataHandle: GetObjects(slotId, CKO_DATA)) + foreach(const CK_OBJECT_HANDLE & dataHandle, GetObjects(slotId, CKO_DATA)) { SecurityTokenKeyfile keyfile; keyfile.Handle = dataHandle; diff --git a/src/Core/Unix/CoreUnix.cpp b/src/Core/Unix/CoreUnix.cpp index c23df499..2ab57ec1 100644 --- a/src/Core/Unix/CoreUnix.cpp +++ b/src/Core/Unix/CoreUnix.cpp @@ -1440,8 +1440,8 @@ namespace VeraCrypt while (getline(ss, token, ':')) { // remove any trailing slashes from the token - while (!token.empty() && token.back() == '/') - token.pop_back(); + while (!token.empty() && token[token.length() - 1] == '/') + token.erase(token.length() - 1); if (token.empty()) continue; @@ -1459,8 +1459,8 @@ namespace VeraCrypt free(resolvedEntry); // remove any trailing slashes from the token - while (!entryPath.empty() && entryPath.back() == '/') - entryPath.pop_back(); + while (!entryPath.empty() && entryPath[entryPath.length() - 1] == '/') + entryPath.erase(entryPath.length() - 1); // perform check again if the resolved path is different from the original (symlink) if (dirPath == entryPath || dirPath.find(entryPath + "/") == 0)