mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Fix argument key-value pair parsing cases
This commit is contained in:
committed by
Felipe Zimmerle
parent
68c995ca98
commit
9cac167faf
@@ -294,17 +294,9 @@ bool Transaction::extractArguments(const std::string &orig,
|
||||
|
||||
std::string key;
|
||||
std::string value;
|
||||
std::vector<std::string> key_value = utils::string::ssplit(t, sep2);
|
||||
for (auto& a : key_value) {
|
||||
if (i == 0) {
|
||||
key = a;
|
||||
} else if (i == 1) {
|
||||
value = a;
|
||||
} else {
|
||||
value = value + "=" + a;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
std::pair<std::string, std::string> key_value_pair = utils::string::ssplit_pair(t, sep2);
|
||||
key = key_value_pair.first;
|
||||
value = key_value_pair.second;
|
||||
|
||||
key_s = (key.length() + 1);
|
||||
value_s = (value.length() + 1);
|
||||
|
@@ -182,20 +182,29 @@ std::vector<std::string> ssplit(std::string str, char delimiter) {
|
||||
std::vector<std::string> internal;
|
||||
std::stringstream ss(str); // Turn the string into a stream.
|
||||
std::string tok;
|
||||
ssize_t n = str.length();
|
||||
int i = 0;
|
||||
|
||||
while (getline(ss, tok, delimiter)) {
|
||||
n -= tok.length();
|
||||
if (i > 0) n--;
|
||||
internal.push_back(n == 1 ? tok + delimiter : tok);
|
||||
i++;
|
||||
internal.push_back(tok);
|
||||
}
|
||||
|
||||
return internal;
|
||||
}
|
||||
|
||||
|
||||
std::pair<std::string, std::string> ssplit_pair(const std::string& str, char delimiter) {
|
||||
std::stringstream ss(str); // Turn the string into a stream.
|
||||
std::string key;
|
||||
std::string value;
|
||||
|
||||
getline(ss, key, delimiter);
|
||||
if (key.length() < str.length()) {
|
||||
value = str.substr(key.length()+1);
|
||||
}
|
||||
|
||||
return std::make_pair(key, value);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> split(std::string str, char delimiter) {
|
||||
std::vector<std::string> internal = ssplit(str, delimiter);
|
||||
|
||||
|
@@ -65,6 +65,7 @@ std::string toHexIfNeeded(const std::string &str);
|
||||
std::string tolower(std::string str);
|
||||
std::string toupper(std::string str);
|
||||
std::vector<std::string> ssplit(std::string str, char delimiter);
|
||||
std::pair<std::string, std::string> ssplit_pair(const std::string& str, char delimiter);
|
||||
std::vector<std::string> split(std::string str, char delimiter);
|
||||
void chomp(std::string *str);
|
||||
void replaceAll(std::string *str, const std::string& from,
|
||||
|
Reference in New Issue
Block a user