Skip to content

Commit

Permalink
Merge pull request #3322 from airween/v3/validatebyterange
Browse files Browse the repository at this point in the history
fix: add value checking to @validateByteRange
  • Loading branch information
airween authored Jan 6, 2025
2 parents f260a75 + 9158477 commit 9e685bf
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/operators/validate_byte_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
"' into a number");
return false;
}
if ((start < 0) || (start > 255)) {
error->assign("Invalid byte value: " +
std::to_string(start));
return false;
}
table[start >> 3] = (table[start >> 3] | (1 << (start & 0x7)));
return true;
}
Expand Down Expand Up @@ -87,21 +92,29 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
bool ValidateByteRange::init(const std::string &file,
std::string *error) {
size_t pos = m_param.find_first_of(",");
bool rc;

if (pos == std::string::npos) {
getRange(m_param, error);
rc = getRange(m_param, error);
} else {
getRange(std::string(m_param, 0, pos), error);
rc = getRange(std::string(m_param, 0, pos), error);
}

if (rc == false) {
return false;
}

while (pos != std::string::npos) {
size_t next_pos = m_param.find_first_of(",", pos + 1);

if (next_pos == std::string::npos) {
getRange(std::string(m_param, pos + 1, m_param.length() -
rc = getRange(std::string(m_param, pos + 1, m_param.length() -
(pos + 1)), error);
} else {
getRange(std::string(m_param, pos + 1, next_pos - (pos + 1)), error);
rc = getRange(std::string(m_param, pos + 1, next_pos - (pos + 1)), error);
}
if (rc == false) {
return false;
}
pos = next_pos;
}
Expand Down

0 comments on commit 9e685bf

Please sign in to comment.