Skip to content

Commit 9e685bf

Browse files
authored
Merge pull request #3322 from airween/v3/validatebyterange
fix: add value checking to @validateByteRange
2 parents f260a75 + 9158477 commit 9e685bf

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/operators/validate_byte_range.cc

+17-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
3737
"' into a number");
3838
return false;
3939
}
40+
if ((start < 0) || (start > 255)) {
41+
error->assign("Invalid byte value: " +
42+
std::to_string(start));
43+
return false;
44+
}
4045
table[start >> 3] = (table[start >> 3] | (1 << (start & 0x7)));
4146
return true;
4247
}
@@ -87,21 +92,29 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
8792
bool ValidateByteRange::init(const std::string &file,
8893
std::string *error) {
8994
size_t pos = m_param.find_first_of(",");
95+
bool rc;
9096

9197
if (pos == std::string::npos) {
92-
getRange(m_param, error);
98+
rc = getRange(m_param, error);
9399
} else {
94-
getRange(std::string(m_param, 0, pos), error);
100+
rc = getRange(std::string(m_param, 0, pos), error);
101+
}
102+
103+
if (rc == false) {
104+
return false;
95105
}
96106

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

100110
if (next_pos == std::string::npos) {
101-
getRange(std::string(m_param, pos + 1, m_param.length() -
111+
rc = getRange(std::string(m_param, pos + 1, m_param.length() -
102112
(pos + 1)), error);
103113
} else {
104-
getRange(std::string(m_param, pos + 1, next_pos - (pos + 1)), error);
114+
rc = getRange(std::string(m_param, pos + 1, next_pos - (pos + 1)), error);
115+
}
116+
if (rc == false) {
117+
return false;
105118
}
106119
pos = next_pos;
107120
}

0 commit comments

Comments
 (0)