From f986b5956bc2f98d58f725bc6d7bf73aebf1f076 Mon Sep 17 00:00:00 2001 From: Xiaoniu Date: Mon, 28 Jun 2021 07:51:57 +0800 Subject: [PATCH] check 'vhost' validity in 'http raw dvr api' (#2435) --- trunk/src/app/srs_app_config.cpp | 8 ++++++++ trunk/src/app/srs_app_http_api.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index e2d8d698b..c60b1754b 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3171,6 +3171,8 @@ srs_error_t SrsConfig::raw_disable_vhost(string vhost, bool& applied) applied = false; SrsConfDirective* conf = root->get("vhost", vhost); + srs_assert(conf); + conf->get_or_create("enabled")->set_arg0("off"); if ((err = do_reload_vhost_removed(vhost)) != srs_success) { @@ -3189,6 +3191,8 @@ srs_error_t SrsConfig::raw_enable_vhost(string vhost, bool& applied) applied = false; SrsConfDirective* conf = root->get("vhost", vhost); + srs_assert(conf); + conf->get_or_create("enabled")->set_arg0("on"); if ((err = do_reload_vhost_added(vhost)) != srs_success) { @@ -3207,6 +3211,8 @@ srs_error_t SrsConfig::raw_enable_dvr(string vhost, string stream, bool& applied applied = false; SrsConfDirective* conf = root->get("vhost", vhost); + srs_assert(conf); + conf = conf->get_or_create("dvr")->get_or_create("dvr_apply"); if (conf->args.size() == 1 && (conf->arg0() == "all" || conf->arg0() == "none")) { @@ -3233,6 +3239,8 @@ srs_error_t SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applie applied = false; SrsConfDirective* conf = root->get("vhost", vhost); + srs_assert(conf); + conf = conf->get_or_create("dvr")->get_or_create("dvr_apply"); std::vector::iterator it; diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 5087a825e..81c7add7e 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1206,7 +1206,12 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* if (action != "enable" && action != "disable") { return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); } - + + // the vhost must exists. + if (!_srs_config->get_vhost(value, false)) { + return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS); + } + if (!_srs_config->get_dvr_enabled(value)) { return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED); }