Skip to content

[ext_proc] request_body_mode override for stream with a request without a body causes seg fault #17354

@ikepolinsky

Description

@ikepolinsky

Received permission to make this crash a public issue from @htuch

Title: request_body_mode override for stream with a request without a body causes seg fault

Description:
The following scenario causes a seg fault:

  1. Downstream sends a GET request to Envoy with no HTTP Body
  2. ext_proc filter sends ProcessingRequest message to external process with request_headers set
  3. External process replies with ProcessingResponse message setting the ProcessingMode mode_override to BUFFER the request_body
  4. A seg fault occurs because the downstream request does not contain a body.

If the downstream request contains a body (e.g., POST request with data) a crash does not occur.

The following test case can be added to test/extensions/filters/http/ext_proc/ext_proc_integration_test.cc to recreate the seg fault

// Test how the filter responds when asked to buffer a request body for a GET
// request with no body.
TEST_P(ExtProcIntegrationTest, BufferBodyOverrideNoRequestBody) {
  initializeConfig();
  HttpIntegrationTest::initialize();
  auto response = sendDownstreamRequest(absl::nullopt);

  ProcessingRequest request_headers_msg;
  waitForFirstMessage(request_headers_msg);
  processor_stream_->startGrpcStream();
  ProcessingResponse resp;
  resp.mutable_request_headers();
  auto* proc_mode = resp.mutable_mode_override();
  proc_mode->set_request_body_mode(ProcessingMode::BUFFERED);
  processor_stream_->sendGrpcMessage(resp);

  handleUpstreamRequest();

  processor_stream_->finishGrpcStream(Grpc::Status::Ok);

  // TODO: fix what should be the expected behavior here?
  verifyDownstreamResponse(*response, 500);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions