Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug](backend-options) fix use after free on BackendOptions::get_local_backend() #35634

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions be/src/service/backend_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ static const std::string PRIORITY_CIDR_SEPARATOR = ";";

std::string BackendOptions::_s_localhost;
std::vector<CIDR> BackendOptions::_s_priority_cidrs;
TBackend BackendOptions::_backend;
bool BackendOptions::_bind_ipv6 = false;
const char* _service_bind_address = "0.0.0.0";
int64_t BackendOptions::_s_backend_id = 0;

bool BackendOptions::init() {
if (!analyze_priority_cidrs(config::priority_networks, &_s_priority_cidrs)) {
Expand Down Expand Up @@ -72,15 +72,17 @@ std::string BackendOptions::get_be_endpoint() {
}

TBackend BackendOptions::get_local_backend() {
_backend.__set_host(_s_localhost);
_backend.__set_be_port(config::be_port);
_backend.__set_http_port(config::webserver_port);
_backend.__set_brpc_port(config::brpc_port);
return _backend;
TBackend backend;
backend.__set_host(_s_localhost);
backend.__set_be_port(config::be_port);
backend.__set_http_port(config::webserver_port);
backend.__set_brpc_port(config::brpc_port);
backend.__set_id(_s_backend_id);
return backend;
}

void BackendOptions::set_backend_id(int64_t backend_id) {
_backend.__set_id(backend_id);
_s_backend_id = backend_id;
}

void BackendOptions::set_localhost(const std::string& host) {
Expand Down
5 changes: 2 additions & 3 deletions be/src/service/backend_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CIDR;

class BackendOptions {
public:
BackendOptions() = delete;
static bool init();
static const std::string& get_localhost();
static std::string get_be_endpoint();
Expand All @@ -49,11 +50,9 @@ class BackendOptions {
static bool is_in_prior_network(const std::string& ip);

static std::string _s_localhost;
static TBackend _backend;
static int64_t _s_backend_id;
static std::vector<CIDR> _s_priority_cidrs;
static bool _bind_ipv6;

DISALLOW_COPY_AND_ASSIGN(BackendOptions);
};

} // namespace doris
Loading