Skip to content

Commit

Permalink
config: escape File= and Plugin= directives
Browse files Browse the repository at this point in the history
Plugin= and Fileset= directives of Filesets were not
correctly escaped in FILESETRES::print_config.

Additionally, the Plugin= entries were not printed
with quotes.
  • Loading branch information
pstorz authored and Marco van Wieringen committed Jul 28, 2016
1 parent 11e6db9 commit 01cae66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/dird/dird_conf.c
Expand Up @@ -1786,6 +1786,12 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
POOL_MEM temp;
const char *p;

/* escape strings */
POOLMEM *buf;
int len;
buf = get_pool_memory(PM_NAME);


Dmsg0(200,"FILESETRES::print_config\n");

Mmsg(temp, "FileSet {\n");
Expand Down Expand Up @@ -2105,7 +2111,10 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
*/
if (incexe->name_list.size()) {
for (int l = 0; l < incexe->name_list.size(); l++) {
Mmsg(temp, "File = \"%s\"\n", incexe->name_list.get(l));
len = strlen((char*)incexe->name_list.get(l));
buf = check_pool_memory_size(buf, len * 2);
escape_string(buf, (char*)incexe->name_list.get(l), len);
Mmsg(temp, "File = \"%s\"\n", buf);
indent_config_item(cfg_str, 2, temp.c_str());
}
}
Expand All @@ -2115,7 +2124,10 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
*/
if (incexe->plugin_list.size()) {
for (int l = 0; l < incexe->plugin_list.size(); l++) {
Mmsg(temp, "Plugin = %s\n", incexe->plugin_list.get(l));
len = strlen((char*)incexe->plugin_list.get(l));
buf = check_pool_memory_size(buf, len * 2);
escape_string(buf, (char*)incexe->plugin_list.get(l), len);
Mmsg(temp, "Plugin = \"%s\"\n", buf);
indent_config_item(cfg_str, 2, temp.c_str());
}
}
Expand Down Expand Up @@ -2149,7 +2161,10 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
indent_config_item(cfg_str, 1, "Exclude {\n");

for (int k = 0; k < incexe->name_list.size(); k++) {
Mmsg(temp, "File = \"%s\"\n", incexe->name_list.get(k));
len = strlen((char*)incexe->name_list.get(k));
buf = check_pool_memory_size(buf, len * 2);
escape_string(buf, (char*)incexe->name_list.get(k), len);
Mmsg(temp, "File = \"%s\"\n", buf);
indent_config_item(cfg_str, 2, temp.c_str());
}

Expand All @@ -2158,6 +2173,8 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
} /* loop over all exclude blocks */
}

free_pool_memory(buf);

pm_strcat(cfg_str, "}\n\n");
pm_strcat(buff, cfg_str.c_str());

Expand Down
5 changes: 5 additions & 0 deletions src/lib/util.c
Expand Up @@ -49,6 +49,11 @@ void escape_string(char *snew, char *old, int len)
*n++ = '\'';
o++;
break;
case '\\':
*n++ = '\\';
*n++ = '\\';
o++;
break;
case 0:
*n++ = '\\';
*n++ = 0;
Expand Down

0 comments on commit 01cae66

Please sign in to comment.