Skip to content

Commit

Permalink
config-parser: export a configuration using -xc can cause a daemon crash
Browse files Browse the repository at this point in the history
- this commit fixes the problem of an uninitialized pointer access to
  the ConfigurationParser object of the respective daemon
  • Loading branch information
franku authored and pstorz committed Oct 9, 2018
1 parent d71b622 commit b5d3762
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion core/src/console/console_conf.cc
Expand Up @@ -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());
Expand Down
22 changes: 11 additions & 11 deletions core/src/dird/dird_conf.cc
Expand Up @@ -3916,52 +3916,52 @@ 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:
res->res_fs.PrintConfig(buf, hide_sensitive_data, verbose);
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:
Expand Down
2 changes: 1 addition & 1 deletion core/src/filed/filed_conf.cc
Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion core/src/lib/parse_conf.cc
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions core/src/lib/parse_conf.h
Expand Up @@ -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 */
};
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 13 additions & 11 deletions core/src/lib/res.cc
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/qt-tray-monitor/tray_conf.cc
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/stored_conf.cc
Expand Up @@ -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());
Expand Down

0 comments on commit b5d3762

Please sign in to comment.