@@ -279,6 +279,17 @@ void set_return_error(const std::string& point, HttpRequest* req) {
279279 HttpChannel::send_reply (req, HttpStatus::OK, " OK" );
280280}
281281
282+ void set_segfault (const std::string& point, HttpRequest* req) {
283+ auto sp = SyncPoint::get_instance ();
284+ sp->set_call_back (point, [point](auto &&) {
285+ LOG (INFO) << " injection point hit, point=" << point << " trigger segfault" ;
286+ // Intentional null dereference to crash the BE for testing.
287+ volatile int * p = nullptr ;
288+ *p = 1 ;
289+ });
290+ HttpChannel::send_reply (req, HttpStatus::OK, " OK" );
291+ }
292+
282293void handle_set (HttpRequest* req) {
283294 auto & point = req->param (" name" );
284295 if (point.empty ()) {
@@ -302,6 +313,9 @@ void handle_set(HttpRequest* req) {
302313 } else if (behavior == " return_error" ) {
303314 set_return_error (point, req);
304315 return ;
316+ } else if (behavior == " segfault" ) {
317+ set_segfault (point, req);
318+ return ;
305319 }
306320 HttpChannel::send_reply (req, HttpStatus::BAD_REQUEST, " unknown behavior: " + behavior);
307321}
@@ -377,13 +391,15 @@ InjectionPointAction::InjectionPointAction() = default;
377391// which is an int, valid values can be found in status.h, e.g. -235 or -230,
378392// if `code` is not present return Status::InternalError. Optional `probability`
379393// determines the percentage of times to inject the error (default 100).
394+ // * segfault: dereference a null pointer to crash BE intentionally
380395// ```
381396// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=sleep&duration=${x_millsec}" # sleep x millisecs
382397// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=return" # return void
383398// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=return_ok" # return ok
384399// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=return_error" # internal error
385400// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=return_error&code=${code}" # -235
386401// curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=return_error&code=${code}&probability=50" # inject with 50% probability
402+ // curl "be_ip:http_port/api/injection_point/set?name=${injection_point_name}&behavior=segfault" # crash BE
387403// ```
388404void InjectionPointAction::handle (HttpRequest* req) {
389405 LOG (INFO) << " handle InjectionPointAction " << req->debug_string ();
0 commit comments