From: Eric Bollengier Date: Mon, 26 Oct 2020 17:30:03 +0000 (+0100) Subject: Fix #6891 Handle empty PluginConfig files X-Git-Tag: Release-11.3.2~891 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce03d5bb5ce376179ae684e310cf7253391558af;p=thirdparty%2Fbacula.git Fix #6891 Handle empty PluginConfig files --- diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index c6de5c2fd..33e1b7370 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -871,8 +871,11 @@ static void plugin_config_save_jcr(UAContext *ua, JCR *jcr, elt = (plugin_config_item *) malloc (sizeof(plugin_config_item)); elt->plugin_name = bstrdup(pname); elt->content = get_pool_memory(PM_FNAME); - ini->dump_results(&elt->content); - jcr->plugin_config->append(elt); + if (ini->dump_results(&elt->content) > 0) { + jcr->plugin_config->append(elt); /* Is not empty */ + } else { + free_plugin_config_item(elt); + } } /* TODO: Allow to have sub-menus Advanced.restore_mode can be diff --git a/bacula/src/lib/ini.c b/bacula/src/lib/ini.c index 0c9b0ab32..8191ba701 100644 --- a/bacula/src/lib/ini.c +++ b/bacula/src/lib/ini.c @@ -267,13 +267,13 @@ int ConfigFile::serialize(POOLMEM **buf) /* Dump the item table content to a text file (used by director) */ int ConfigFile::dump_results(POOLMEM **buf) { - int len; + int len, len_header; POOLMEM *tmp, *tmp2; if (!items) { **buf = 0; return 0; } - len = Mmsg(buf, "# Plugin configuration file\n# Version %d\n", version); + len_header = len = Mmsg(buf, "# Plugin configuration file\n# Version %d\n", version); tmp = get_pool_memory(PM_MESSAGE); tmp2 = get_pool_memory(PM_MESSAGE); @@ -309,13 +309,16 @@ int ConfigFile::dump_results(POOLMEM **buf) free_pool_memory(tmp); free_pool_memory(tmp2); + if (len_header == len) { /* Nothing was generated */ + return 0; + } return len ; } bool ConfigFile::parse() { int token, i; - bool ret = false; + bool ret = true; /* If the file is empty and we don't have required fields, it's ok */ bool found; lc->options |= LOPT_NO_EXTERN;