Fix crashes in FCGI_PARAMS parsing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ example_clock
|
||||
example_simple
|
||||
fastcgi_conn_afl
|
||||
*.o
|
||||
afl_state/findings
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<EFBFBD>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
9))))
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,9 @@ size_t ConstBuffer::ReadMaxLen() const {
|
||||
}
|
||||
|
||||
const char *ConstBuffer::Read(size_t len) {
|
||||
CHECK_LE(len, ReadMaxLen());
|
||||
if (ReadMaxLen() < len) {
|
||||
return nullptr;
|
||||
}
|
||||
const auto *ret = &const_buf_[start_];
|
||||
start_ += len;
|
||||
return ret;
|
||||
|
||||
@@ -82,8 +82,25 @@ int FastCGIConn::Read() {
|
||||
ConstBuffer param_buf(buf_.Read(header->ContentLength()), header->ContentLength());
|
||||
while (param_buf.ReadMaxLen() > 0) {
|
||||
const auto *param_header = param_buf.ReadObj<FastCGIParamHeader>();
|
||||
std::string_view key(param_buf.Read(param_header->key_length), param_header->key_length);
|
||||
std::string_view value(param_buf.Read(param_header->value_length), param_header->value_length);
|
||||
if (!param_header) {
|
||||
LOG(ERROR) << "FCGI_PARAMS missing header";
|
||||
return sock_;
|
||||
}
|
||||
|
||||
const auto *key_buf = param_buf.Read(param_header->key_length);
|
||||
if (!key_buf) {
|
||||
LOG(ERROR) << "FCGI_PARAMS missing key";
|
||||
return sock_;
|
||||
}
|
||||
std::string_view key(key_buf, param_header->key_length);
|
||||
|
||||
const auto *value_buf = param_buf.Read(param_header->value_length);
|
||||
if (!value_buf) {
|
||||
LOG(ERROR) << "FCGI_PARAMS missing value";
|
||||
return sock_;
|
||||
}
|
||||
std::string_view value(value_buf, param_header->value_length);
|
||||
|
||||
if (headers_.find(key) != headers_.end()) {
|
||||
request_->AddParam(key, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user