From b5d376238dd3646b051d2dfede2673bd569b8b92 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 9 Oct 2018 14:02:58 +0200 Subject: [PATCH] config-parser: export a configuration using -xc can cause a daemon crash - this commit fixes the problem of an uninitialized pointer access to the ConfigurationParser object of the respective daemon --- core/src/console/console_conf.cc | 2 +- core/src/dird/dird_conf.cc | 22 +++++++++++----------- core/src/filed/filed_conf.cc | 2 +- core/src/lib/parse_conf.cc | 1 - core/src/lib/parse_conf.h | 6 +++--- core/src/lib/res.cc | 24 +++++++++++++----------- core/src/qt-tray-monitor/tray_conf.cc | 2 +- core/src/stored/stored_conf.cc | 2 +- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/core/src/console/console_conf.cc b/core/src/console/console_conf.cc index dbb3e40d9e0..b9677fa7a7a 100644 --- a/core/src/console/console_conf.cc +++ b/core/src/console/console_conf.cc @@ -147,7 +147,7 @@ static void DumpResource(int type, switch (type) { default: resclass = (BareosResource *)reshdr; - resclass->PrintConfig(buf); + resclass->PrintConfig(buf, *my_config); break; } sendit(sock, "%s", buf.c_str()); diff --git a/core/src/dird/dird_conf.cc b/core/src/dird/dird_conf.cc index d4ebbba538b..b91cb6859dc 100644 --- a/core/src/dird/dird_conf.cc +++ b/core/src/dird/dird_conf.cc @@ -3916,40 +3916,40 @@ static void DumpResource(int type, switch (type) { case R_DIRECTOR: - res->res_dir.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_dir.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_PROFILE: - res->res_profile.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_profile.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_CONSOLE: - res->res_con.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_con.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_COUNTER: - res->res_counter.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_counter.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_CLIENT: - res->res_client.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_client.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_DEVICE: - res->res_dev.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_dev.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_STORAGE: - res->res_store.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_store.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_CATALOG: - res->res_cat.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_cat.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_JOBDEFS: case R_JOB: - res->res_job.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_job.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_FILESET: @@ -3957,11 +3957,11 @@ static void DumpResource(int type, sendit(sock, "%s", buf.c_str()); break; case R_SCHEDULE: - res->res_sch.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_sch.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_POOL: - res->res_pool.PrintConfig(buf, hide_sensitive_data, verbose); + res->res_pool.PrintConfig(buf, *my_config, hide_sensitive_data, verbose); sendit(sock, "%s", buf.c_str()); break; case R_MSGS: diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index d94e880a20f..ce4d6e166f8 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -361,7 +361,7 @@ static void DumpResource(int type, } default: resclass = (BareosResource *)reshdr; - resclass->PrintConfig(buf); + resclass->PrintConfig(buf, *my_config); break; } sendit(sock, "%s", buf.c_str()); diff --git a/core/src/lib/parse_conf.cc b/core/src/lib/parse_conf.cc index 18faa1c53b0..d5801ea6379 100644 --- a/core/src/lib/parse_conf.cc +++ b/core/src/lib/parse_conf.cc @@ -665,7 +665,6 @@ void ConfigurationParser::InitResource(int type, } res_all->hdr.rcode = type; res_all->hdr.refcnt = 1; - res_all->hdr.my_config_ = this; /* * See what pass of the config parsing this is. diff --git a/core/src/lib/parse_conf.h b/core/src/lib/parse_conf.h index bae10de6e5b..61ebfd772f3 100644 --- a/core/src/lib/parse_conf.h +++ b/core/src/lib/parse_conf.h @@ -178,12 +178,11 @@ struct ResourceItem { */ class CommonResourceHeader { public: - CommonResourceHeader *next; /* Pointer to next resource of this type */ + CommonResourceHeader *next; /* Pointer to next resource of this type */ char *name; /* Resource name */ char *desc; /* Resource description */ uint32_t rcode; /* Resource id or type */ int32_t refcnt; /* Reference count for releasing */ - ConfigurationParser *my_config_; /* Pointer to config parser that created this resource */ char item_present[MAX_RES_ITEMS]; /* Set if item is present in conf file */ char inherit_content[MAX_RES_ITEMS]; /* Set if item has inherited content */ }; @@ -327,7 +326,8 @@ class BareosResource { /* Methods */ inline char *name() const { return this->hdr.name; } - bool PrintConfig(PoolMem &buf, bool hide_sensitive_data = false, bool verbose = false); + bool PrintConfig(PoolMem &buf, const ConfigurationParser &my_config, + bool hide_sensitive_data = false, bool verbose = false); /* * validate can be defined by inherited classes, * when special rules for this resource type must be checked. diff --git a/core/src/lib/res.cc b/core/src/lib/res.cc index a0511b243b9..18e4cfa9427 100644 --- a/core/src/lib/res.cc +++ b/core/src/lib/res.cc @@ -1592,7 +1592,8 @@ static bool HasDefaultValue(ResourceItem *item) return is_default; } -bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool verbose) +bool BareosResource::PrintConfig(PoolMem &buff, const ConfigurationParser &my_config, + bool hide_sensitive_data, bool verbose) { PoolMem cfg_str; PoolMem temp; @@ -1604,20 +1605,21 @@ bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool v /* * If entry is not used, then there is nothing to print. */ - if (this->hdr.rcode < (uint32_t)hdr.my_config_->r_first_ || this->hdr.refcnt <= 0) { return true; } - rindex = this->hdr.rcode - hdr.my_config_->r_first_; + if (this->hdr.rcode < (uint32_t)my_config.r_first_ || this->hdr.refcnt <= 0) { return true; } + + rindex = this->hdr.rcode - my_config.r_first_; /* * Make sure the resource class has any items. */ - if (!hdr.my_config_->resources_[rindex].items) { return true; } + if (!my_config.resources_[rindex].items) { return true; } - memcpy(hdr.my_config_->res_all_, this, hdr.my_config_->resources_[rindex].size); + memcpy(my_config.res_all_, this, my_config.resources_[rindex].size); - PmStrcat(cfg_str, hdr.my_config_->res_to_str(this->hdr.rcode)); + PmStrcat(cfg_str, my_config.res_to_str(this->hdr.rcode)); PmStrcat(cfg_str, " {\n"); - items = hdr.my_config_->resources_[rindex].items; + items = my_config.resources_[rindex].items; for (i = 0; items[i].name; i++) { bool print_item = false; @@ -1635,9 +1637,9 @@ bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool v continue; } - if ((items[i].flags & CFG_ITEM_REQUIRED) || !hdr.my_config_->omit_defaults_) { + if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config.omit_defaults_) { /* - * Always print required items or if hdr.my_config_->omit_defaults_ is false + * Always print required items or if my_config.omit_defaults_ is false */ print_item = true; } @@ -1881,8 +1883,8 @@ bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool v /* * This is a non-generic type call back to the daemon to get things printed. */ - if (hdr.my_config_->print_res_) { - hdr.my_config_->print_res_(items, i, cfg_str, hide_sensitive_data, inherited); + if (my_config.print_res_) { + my_config.print_res_(items, i, cfg_str, hide_sensitive_data, inherited); } break; } diff --git a/core/src/qt-tray-monitor/tray_conf.cc b/core/src/qt-tray-monitor/tray_conf.cc index 9e05c454ea8..25fa24d8585 100644 --- a/core/src/qt-tray-monitor/tray_conf.cc +++ b/core/src/qt-tray-monitor/tray_conf.cc @@ -215,7 +215,7 @@ static void DumpResource(int type, switch (type) { default: resclass = (BareosResource *)reshdr; - resclass->PrintConfig(buf); + resclass->PrintConfig(buf, *my_config); break; } sendit(sock, "%s", buf.c_str()); diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index eb7a80b0453..5d694c1d938 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -639,7 +639,7 @@ static void DumpResource(int type, } default: resclass = (BareosResource *)reshdr; - resclass->PrintConfig(buf); + resclass->PrintConfig(buf, *my_config); break; } sendit(sock, "%s", buf.c_str());