From 5878fb0d0e32179803316da1bb5d724c06aeaa5d Mon Sep 17 00:00:00 2001 From: Kory Draughn Date: Sat, 9 Nov 2024 11:46:06 -0500 Subject: [PATCH] [#8045] Use std::tolower() with std::transform() correctly. --- .../irods/authentication_plugin_framework.hpp | 4 ++- .../irods/experimental_plugin_framework.hpp | 7 ++--- lib/core/include/irods/irods_query.hpp | 6 ++-- lib/core/src/clientLogin.cpp | 5 ++- lib/core/src/irods_buffer_encryption.cpp | 10 +++--- lib/hasher/src/checksum.cpp | 31 +++++++------------ plugins/database/src/db_plugin.cpp | 6 +--- server/api/src/rsFileChksum.cpp | 13 ++++---- server/icat/src/icatHighLevelRoutines.cpp | 7 ++--- 9 files changed, 37 insertions(+), 52 deletions(-) diff --git a/lib/core/include/irods/authentication_plugin_framework.hpp b/lib/core/include/irods/authentication_plugin_framework.hpp index 60f05cf651..c019d4ee07 100644 --- a/lib/core/include/irods/authentication_plugin_framework.hpp +++ b/lib/core/include/irods/authentication_plugin_framework.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -117,7 +118,8 @@ namespace irods::experimental::auth using plugin_type = authentication_base; std::string scheme = _scheme; - std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower); + std::transform( + scheme.begin(), scheme.end(), scheme.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); const std::string name = fmt::format("irods_auth_plugin-{}_{}", scheme, _type); diff --git a/lib/core/include/irods/experimental_plugin_framework.hpp b/lib/core/include/irods/experimental_plugin_framework.hpp index 8a80a2aacf..92c646fd40 100644 --- a/lib/core/include/irods/experimental_plugin_framework.hpp +++ b/lib/core/include/irods/experimental_plugin_framework.hpp @@ -15,6 +15,7 @@ // =-=-=-=-=-=-=- // stl includes +#include #include #include #include @@ -145,10 +146,8 @@ namespace irods::experimental::api { static auto resolve_api_plugin(const std::string& operation, const std::string& type) { std::string lower{operation}; - std::transform(lower.begin(), - lower.end(), - lower.begin(), - ::tolower ); + std::transform( + lower.begin(), lower.end(), lower.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); base* plugin{}; auto err = irods::load_plugin( diff --git a/lib/core/include/irods/irods_query.hpp b/lib/core/include/irods/irods_query.hpp index 9d9bf60a57..c9c2f6cc04 100644 --- a/lib/core/include/irods/irods_query.hpp +++ b/lib/core/include/irods/irods_query.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -45,10 +46,7 @@ namespace irods std::string lowered{_str}; std::transform( - lowered.begin(), - lowered.end(), - lowered.begin(), - ::tolower); + lowered.begin(), lowered.end(), lowered.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); if(GEN_STR == lowered) { return GENERAL; diff --git a/lib/core/src/clientLogin.cpp b/lib/core/src/clientLogin.cpp index ad83a2930a..3adc8db14b 100644 --- a/lib/core/src/clientLogin.cpp +++ b/lib/core/src/clientLogin.cpp @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -344,7 +345,9 @@ int clientLogin(rcComm_t* _comm, const char* _context, const char* _scheme_overr // =-=-=-=-=-=-=- // ensure scheme is lower case for comparison std::string lower_scheme = auth_scheme; - std::transform( auth_scheme.begin(), auth_scheme.end(), auth_scheme.begin(), ::tolower ); + std::transform(auth_scheme.begin(), auth_scheme.end(), auth_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); // =-=-=-=-=-=-=- // filter out the pam auth as it is an extra special diff --git a/lib/core/src/irods_buffer_encryption.cpp b/lib/core/src/irods_buffer_encryption.cpp index 7da6063f7a..3ca2da7b9b 100644 --- a/lib/core/src/irods_buffer_encryption.cpp +++ b/lib/core/src/irods_buffer_encryption.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -62,12 +63,9 @@ namespace irods { salt_size_( _salt_sz ), num_hash_rounds_( _num_rnds ), algorithm_( _algo ) { - - std::transform( - algorithm_.begin(), - algorithm_.end(), - algorithm_.begin(), - ::tolower ); + std::transform(algorithm_.begin(), algorithm_.end(), algorithm_.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); // =-=-=-=-=-=-=- // select some sane defaults diff --git a/lib/hasher/src/checksum.cpp b/lib/hasher/src/checksum.cpp index ddfda3840e..7a526ebdd3 100644 --- a/lib/hasher/src/checksum.cpp +++ b/lib/hasher/src/checksum.cpp @@ -9,6 +9,7 @@ #include "irods/rodsKeyWdDef.h" #include "irods/rcMisc.h" +#include #include #include #include @@ -55,11 +56,9 @@ int chksumLocFile( env_policy = env.rodsMatchHashPolicy; // =-=-=-=-=-=-=- // hash scheme keywords are all lowercase - std::transform( - env_scheme.begin(), - env_scheme.end(), - env_scheme.begin(), - ::tolower ); + std::transform(env_scheme.begin(), env_scheme.end(), env_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); } // =-=-=-=-=-=-=- @@ -71,11 +70,9 @@ int chksumLocFile( hash_scheme = _hash_scheme; // =-=-=-=-=-=-=- // hash scheme keywords are all lowercase - std::transform( - hash_scheme.begin(), - hash_scheme.end(), - hash_scheme.begin(), - ::tolower ); + std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); } else { hash_scheme = env_scheme; @@ -84,17 +81,11 @@ int chksumLocFile( // =-=-=-=-=-=-=- // hash scheme keywords are all lowercase + std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); std::transform( - hash_scheme.begin(), - hash_scheme.end(), - hash_scheme.begin(), - ::tolower ); - std::transform( - env_scheme.begin(), - env_scheme.end(), - env_scheme.begin(), - ::tolower ); - + env_scheme.begin(), env_scheme.end(), env_scheme.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); // =-=-=-=-=-=-=- // verify checksum scheme against configuration diff --git a/plugins/database/src/db_plugin.cpp b/plugins/database/src/db_plugin.cpp index 275602ab17..7b3a8474cc 100644 --- a/plugins/database/src/db_plugin.cpp +++ b/plugins/database/src/db_plugin.cpp @@ -2023,11 +2023,7 @@ irods::error db_debug_op( // =-=-=-=-=-=-=- // run tolower on mode std::string mode( _mode ); - std::transform( - mode.begin(), - mode.end(), - mode.begin(), - ::tolower ); + std::transform(mode.begin(), mode.end(), mode.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); // =-=-=-=-=-=-=- // if mode contains 'sql' then turn SQL logging on diff --git a/server/api/src/rsFileChksum.cpp b/server/api/src/rsFileChksum.cpp index eca5ae3a3d..5e23b7635b 100644 --- a/server/api/src/rsFileChksum.cpp +++ b/server/api/src/rsFileChksum.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -128,11 +129,9 @@ int fileChksum(rsComm_t* rsComm, } catch ( const irods::exception& ) {} // make sure the read parameter is lowercased - std::transform( - hash_scheme.begin(), - hash_scheme.end(), - hash_scheme.begin(), - ::tolower ); + std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); std::string hash_policy; try { @@ -302,7 +301,9 @@ int file_checksum(RsComm* _comm, catch (const irods::exception&) {} // Make sure the read parameter is lowercased. - std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), ::tolower); + std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) { + return std::tolower(_ch); + }); std::string_view hash_policy; try { diff --git a/server/icat/src/icatHighLevelRoutines.cpp b/server/icat/src/icatHighLevelRoutines.cpp index 29b3e6423a..8354056b3b 100644 --- a/server/icat/src/icatHighLevelRoutines.cpp +++ b/server/icat/src/icatHighLevelRoutines.cpp @@ -25,6 +25,7 @@ // =-=-=-=-=-=-=- // stl includes +#include // For std::tolower #include #include #include @@ -50,11 +51,7 @@ int chlDebug( // =-=-=-=-=-=-=- // run tolower on mode std::string mode( _mode ); - std::transform( - mode.begin(), - mode.end(), - mode.begin(), - ::tolower ); + std::transform(mode.begin(), mode.end(), mode.begin(), [](unsigned char _ch) { return std::tolower(_ch); }); // =-=-=-=-=-=-=- // if mode contains 'sql' then turn SQL logging on