Skip to content

Commit 49b7ea9

Browse files
author
Felipe Zimmerle
committed
Adds a set of sanity checks to validate API inputs (1 of 2)
1 parent 5a32b38 commit 49b7ea9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/transaction.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int Transaction::processConnection(const char *client, int cPort,
235235
bool Transaction::extractArguments(const std::string &orig,
236236
const std::string& buf, size_t offset) {
237237
char sep1 = '&';
238-
std::vector<std::string> key_value_sets = utils::string::split(buf, sep1);
238+
std::vector<std::string> key_value_sets = utils::string::ssplit(buf, sep1);
239239

240240
for (std::string t : key_value_sets) {
241241
char sep2 = '=';
@@ -247,7 +247,7 @@ bool Transaction::extractArguments(const std::string &orig,
247247

248248
std::string key;
249249
std::string value;
250-
std::vector<std::string> key_value = utils::string::split(t, sep2);
250+
std::vector<std::string> key_value = utils::string::ssplit(t, sep2);
251251
for (auto& a : key_value) {
252252
if (i == 0) {
253253
key = a;
@@ -515,7 +515,7 @@ int Transaction::addRequestHeader(const std::string& key,
515515

516516
if (keyl == "cookie") {
517517
size_t localOffset = m_variableOffset;
518-
std::vector<std::string> cookies = utils::string::split(value, ';');
518+
std::vector<std::string> cookies = utils::string::ssplit(value, ';');
519519
for (const std::string &c : cookies) {
520520
std::vector<std::string> s = utils::string::split(c,
521521
'=');

src/utils/string.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ std::string toupper(std::string str) {
170170
}
171171

172172

173-
std::vector<std::string> split(std::string str, char delimiter) {
173+
std::vector<std::string> ssplit(std::string str, char delimiter) {
174174
std::vector<std::string> internal;
175175
std::stringstream ss(str); // Turn the string into a stream.
176176
std::string tok;
@@ -183,6 +183,17 @@ std::vector<std::string> split(std::string str, char delimiter) {
183183
}
184184

185185

186+
std::vector<std::string> split(std::string str, char delimiter) {
187+
std::vector<std::string> internal = ssplit(str, delimiter);
188+
189+
if (internal.size() == 0) {
190+
internal.push_back(str);
191+
}
192+
193+
return internal;
194+
}
195+
196+
186197
void chomp(std::string *str) {
187198
std::string::size_type pos = str->find_last_not_of("\n\r");
188199
if (pos != std::string::npos) {

src/utils/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ std::string string_to_hex(const std::string& input);
6464
std::string toHexIfNeeded(const std::string &str);
6565
std::string tolower(std::string str);
6666
std::string toupper(std::string str);
67+
std::vector<std::string> ssplit(std::string str, char delimiter);
6768
std::vector<std::string> split(std::string str, char delimiter);
6869
void chomp(std::string *str);
6970
void replaceAll(std::string *str, const std::string& from,

0 commit comments

Comments
 (0)